unixoid-challenge 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 18d85ad45d8ef76a1b9dc886b0ed47394004a5b4
4
- data.tar.gz: 3eb07e2b2596fbd41aa7eb369447619000108717
3
+ metadata.gz: fb0161cd90643076d4f2b453a48bfc1542916857
4
+ data.tar.gz: 2e3d355bc69d6d8efedb5c7b01173e02998d0f88
5
5
  SHA512:
6
- metadata.gz: 0ef798ea0f8f701709a1748fa5db108fce1dc05c5fa1095dbff167c5fdd39cdd8704c25a3149a9cc13573a716e71ddf80d932e2efb6c79a156c17c4eac9698a1
7
- data.tar.gz: f4cac2700e00c819f709078e90fd62d795acde897d2d7b9aa85be0f47199b89c14f7859437e9a0108212ccf49d2f61eeae705188295c08018ea4dd0068663f8d
6
+ metadata.gz: e674e0ff18ad0057dc87906755c72725f52b92e339309e5b73b91ddc7ebd45581368846c8ee32e3321d22c9f0c256aab50f3d81750353d9a0482baf2a65b20ee
7
+ data.tar.gz: ec67b362cd57303a8aa2c1abc6ef2bcfb7f9e04892ffcb5ba13483988cad250f8d3cfbd39f681c45a93bbf81b904bca25b40af450029b81df5a42586c6853e50
data/README.md ADDED
@@ -0,0 +1,62 @@
1
+ Unixoid Challenge
2
+ =================
3
+
4
+ Instructions
5
+ ------------
6
+
7
+ * Test time: 1 hour (you can take longer, don’t worry)
8
+ * Feel free to use google, your notes, books, etc. but work on your own
9
+ * Obviously don't use Sublime Text, Finder or similar tools – only the command-line
10
+ * You'll almost certainly need to Google some things. This is deliberate.
11
+ * Upon completion of this challenge (or any time you are taking a break), please use the `history` command to see a list of the commands you have made on the command line. If you save these details into a text file they can be a useful reference.
12
+
13
+ Tasks:
14
+ ------
15
+
16
+ First navigate on the command line to your Desktop directory, and then create a temporary directory using the following command:
17
+
18
+ ```sh
19
+ mkdir temp
20
+ ```
21
+
22
+ Then change into that directory using this next command:
23
+
24
+ ```sh
25
+ cd temp
26
+ ```
27
+
28
+ Now use your command line skills to complete the following:
29
+
30
+ 1. Using one command, create a directory structure "my/private/files"
31
+ 2. Using one command, create a directory structure "my/public/files"
32
+ 3. Create an empty file 't-vars.env' in my/private/files
33
+ 4. Using command-line only add the line "List of env vars that begin with T" to the file, make sure it ends with a newline
34
+ 5. List all env variables that begin with "T" (hint: you'll need a regex that includes the marker of the start of the line) and append them to the end of the file
35
+ 6. Export a new variable TESTING_MAKERS=working in such a way that it is still available when you open a new shell
36
+ 7. Open a new terminal window, check that a new variable is available
37
+ 8. Output the count of the variables that begin with T to a new file my/public/files/t-vars.count, e.g. "Overall count: 5" (hint: you'll need to use 'command substitution' in bash)
38
+ 9. Change the permissions of the my/private/files/t-vars.env to make sure that only the owner can read and write the file
39
+ 10. Change the permissions of the my/private/files directory to make sure that only the owner can change into it
40
+ 11. Give read and write permissions to all users on my/public/files/t-vars.count
41
+ 12. Create another file my/public/files/text-files-count.txt and output the number of text files in your home directory (recursively) into that file
42
+ 13. Create another file my/private/files/first-three-env.txt and output the first three env variables from a list of all of them sorted alphabetically
43
+ 14. Create another file my/private/files/commands.txt and output the contents of the `history` command to that file
44
+
45
+ Checking and submitting your progress
46
+ -------------------------------------
47
+
48
+ First, you will need to install the `unixoid-challenge` gem, like this:
49
+
50
+ ```sh
51
+ gem install unixoid-challenge
52
+ ```
53
+
54
+ At any point while going through the challenge you can check your progress by running:
55
+
56
+ ```sh
57
+ unixoid-challenge
58
+ ```
59
+
60
+ __(make sure you are in the same directory that you completed the challenge in)__
61
+
62
+ This will tell you if you've completed the task, or which of the tasks above you still need to complete. It will also submit your results to GitHub (you'll need your username and password that you use to login to GitHub) so we can track your progress.
@@ -2,6 +2,6 @@
2
2
 
3
3
  require 'rubygems'
4
4
  require 'rspec'
5
- require 'unixoid_challenge'
5
+ require 'unixoid'
6
6
 
7
- UnixoidChallenge.run
7
+ Unixoid::Controller.run
data/bin/unixoid-debug ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'unixoid'
5
+
6
+ Unixoid::Controller.debug
File without changes
@@ -0,0 +1,20 @@
1
+ module Unixoid
2
+ class Challenge
3
+
4
+ RESULTS_FILE = 'unixoid_results.txt'
5
+
6
+ def self.run_specs
7
+ new.run_specs
8
+ end
9
+
10
+ def run_specs
11
+ Runner.run("rspec --out #{RESULTS_FILE} -fp #{spec_file}", outcodes: [0,1])
12
+ end
13
+
14
+ private
15
+
16
+ def spec_file
17
+ File.join(File.dirname(__FILE__), '..', '..','challenge_spec.rb')
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,59 @@
1
+ class ChallengeResult
2
+
3
+ STATUSES = [:complete, :attempted, :unattempted]
4
+
5
+ PASS_CHAR = '.'
6
+
7
+ def initialize(challenge)
8
+ @result = parse(challenge)
9
+ end
10
+
11
+ def status
12
+ STATUSES.find do |status|
13
+ send("#{status}?")
14
+ end
15
+ end
16
+
17
+ def failures
18
+ failing_test_numbers.compact
19
+ end
20
+
21
+ private
22
+
23
+ attr_reader :result
24
+
25
+ def complete?
26
+ passes.length == total_tests
27
+ end
28
+
29
+ def attempted?
30
+ passes.any?
31
+ end
32
+
33
+ def unattempted?
34
+ passes.empty?
35
+ end
36
+
37
+ def parse(challenge)
38
+ challenge.split("\n").first.chars
39
+ end
40
+
41
+ def passes
42
+ result.select { |test| passed(test) }
43
+ end
44
+
45
+ def passed(test)
46
+ test == PASS_CHAR
47
+ end
48
+
49
+ def total_tests
50
+ result.length
51
+ end
52
+
53
+ def failing_test_numbers
54
+ @result.map.with_index do |test, index|
55
+ next if passed(test)
56
+ index + 1
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,17 @@
1
+ class String
2
+ def colorize(color_code)
3
+ "\e[#{color_code}m#{self}\e[0m"
4
+ end
5
+
6
+ def red
7
+ colorize(31)
8
+ end
9
+
10
+ def green
11
+ colorize(32)
12
+ end
13
+
14
+ def yellow
15
+ colorize(33)
16
+ end
17
+ end
@@ -0,0 +1,70 @@
1
+ module Unixoid
2
+ class Controller
3
+
4
+ def self.run
5
+ results = run_challenge
6
+ final_result(results)
7
+ puts "Submitting your results to Makers Academy..."
8
+ push_to_github(Challenge::RESULTS_FILE)
9
+ end
10
+
11
+ def self.debug
12
+ puts "Submitting your history to Makers Academy so we can help you debug..."
13
+ create_history_file
14
+ push_to_github('commands.txt')
15
+ end
16
+
17
+ private
18
+
19
+ class << self
20
+
21
+ def push_to_github(file)
22
+ github = Github.create_repo
23
+ auth_fail! unless github.authenticated?
24
+ puts "Submitting..."
25
+ Git.submit(file, github)
26
+ puts "Submitted!"
27
+ end
28
+
29
+ def run_challenge
30
+ challenge = Challenge.run_specs
31
+ ChallengeResult.new(challenge)
32
+ end
33
+
34
+ def create_history_file
35
+ Runner.run('cp ~/.bash_history commands.txt')
36
+ end
37
+
38
+ def final_result(results)
39
+ puts render_results(results)
40
+ end
41
+
42
+ def auth_fail!
43
+ puts 'Incorrect login details. Please run unixoid-challenge again'.red
44
+ exit 1
45
+ end
46
+
47
+ def render_results(results)
48
+ case results.status
49
+ when :complete
50
+ 'Congratulations, you have successfully completed the Unixoid Challenge!'.green
51
+ when :attempted
52
+ attempted(results).yellow
53
+ when :unattempted
54
+ puts 'Looks like you have not tried the challenge. Give it a go and then re-submit'.red
55
+ exit 0
56
+ end
57
+ end
58
+
59
+ def attempted(results)
60
+ %{
61
+ Almost there! Feel free to try again and re-submit
62
+
63
+ The following answers need to be corrected:
64
+
65
+ #{results.failures.join(", ")}
66
+ }
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,64 @@
1
+ require 'forwardable'
2
+ require 'uri'
3
+
4
+ module Unixoid
5
+
6
+ class Git
7
+
8
+ extend Forwardable
9
+
10
+ delegate run: :@runner
11
+
12
+ def initialize(github)
13
+ @github = github
14
+ @runner = Runner.new
15
+ end
16
+
17
+ def self.submit(file, github)
18
+ new(github).submit(file)
19
+ end
20
+
21
+ def submit(file)
22
+ create_repo
23
+ add(file)
24
+ commit_results
25
+ add_remote
26
+ push_results
27
+ remove_remote
28
+ end
29
+
30
+ def create_repo
31
+ run('git init')
32
+ end
33
+
34
+ def add(file)
35
+ run("git add #{file}")
36
+ end
37
+
38
+ def commit_results
39
+ run("git commit -m 'Unixoid submission'")
40
+ end
41
+
42
+ def add_remote
43
+ run("git remote add origin https://#{username}:#{password}@github.com/#{username}/unixoid_submission.git")
44
+ end
45
+
46
+ def push_results
47
+ run('git push --force -u origin master')
48
+ end
49
+
50
+ def remove_remote
51
+ run('git remote rm origin')
52
+ end
53
+
54
+ private
55
+
56
+ def username
57
+ URI.encode(@github.username)
58
+ end
59
+
60
+ def password
61
+ URI.encode(@github.password)
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,62 @@
1
+ require 'io/console'
2
+ require 'json'
3
+
4
+ module Unixoid
5
+
6
+ class Github
7
+
8
+ GITHUB_URL = 'https://api.github.com/user/repos'
9
+ REPO_NAME = 'unixoid_submission'
10
+
11
+ def initialize
12
+ @runner = Runner.new
13
+ end
14
+
15
+ def self.create_repo
16
+ new.create_repo
17
+ end
18
+
19
+ def create_repo
20
+ parse @runner.run(command)
21
+ self
22
+ end
23
+
24
+ def username
25
+ @username ||= ask_for_username
26
+ end
27
+
28
+ def password
29
+ @password ||= ask_for_password
30
+ end
31
+
32
+ def authenticated?
33
+ @response && @response['message'] != "Bad credentials"
34
+ end
35
+
36
+ private
37
+
38
+ def command
39
+ %Q{curl -u "#{username}:#{password}" #{GITHUB_URL} -d '{"name": "#{REPO_NAME}"}'}
40
+ end
41
+
42
+ def parse(response)
43
+ @response = parse_json(response)
44
+ end
45
+
46
+ def parse_json(response)
47
+ begin
48
+ JSON.parse(response)
49
+ rescue JSON::ParseError; end
50
+ end
51
+
52
+ def ask_for_username
53
+ puts "Please enter your Github username:"
54
+ $stdin.gets.chomp
55
+ end
56
+
57
+ def ask_for_password
58
+ puts "Please enter your Github password:"
59
+ $stdin.noecho(&:gets).chomp
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,32 @@
1
+ require 'cocaine'
2
+ require 'logger'
3
+
4
+ module Unixoid
5
+
6
+ class Runner
7
+
8
+ LOG_FILE = 'logfile.log'
9
+
10
+ def initialize
11
+ @logger = Logger.new(LOG_FILE)
12
+ end
13
+
14
+ def self.run(command, opts = {})
15
+ new.run(command, opts)
16
+ end
17
+
18
+ def run(command, outcodes: [0])
19
+ line = Cocaine::CommandLine.new(command, "", expected_outcodes: outcodes, swallow_stderr: true)
20
+ begin
21
+ log(:info, line.run)
22
+ rescue Cocaine::ExitStatusError => error
23
+ log(:error, error.message)
24
+ end
25
+ end
26
+
27
+ def log(level, message)
28
+ @logger.send(level, message)
29
+ message
30
+ end
31
+ end
32
+ end
data/lib/unixoid.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'unixoid/controller'
2
+ require 'unixoid/runner'
3
+ require 'unixoid/challenge'
4
+ require 'unixoid/github'
5
+ require 'unixoid/git'
6
+ require 'unixoid/colorize'
7
+ require 'unixoid/challenge_result'
8
+
9
+ module Unixoid
10
+ end
metadata CHANGED
@@ -1,11 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unixoid-challenge
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Joseph
8
8
  - Dan Le Dosquet-Bergquist
9
+ - Leo Allen
10
+ - Spike Lindsey
9
11
  autorequire:
10
12
  bindir: bin
11
13
  cert_chain: []
@@ -15,28 +17,53 @@ dependencies:
15
17
  name: rspec
16
18
  requirement: !ruby/object:Gem::Requirement
17
19
  requirements:
18
- - - ">="
20
+ - - "~>"
19
21
  - !ruby/object:Gem::Version
20
22
  version: '3'
21
23
  type: :runtime
22
24
  prerelease: false
23
25
  version_requirements: !ruby/object:Gem::Requirement
24
26
  requirements:
25
- - - ">="
27
+ - - "~>"
26
28
  - !ruby/object:Gem::Version
27
29
  version: '3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: cocaine
32
+ requirement: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - "~>"
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
28
44
  description: A gem to assess your performance on the unixoid challenge
29
45
  email: sam@makersacademy.com
30
46
  executables:
31
47
  - unixoid-challenge
48
+ - unixoid-debug
32
49
  extensions: []
33
50
  extra_rdoc_files: []
34
51
  files:
52
+ - README.md
35
53
  - bin/unixoid-challenge
36
- - lib/unixoid_challenge.rb
37
- - spec/unixoid_spec.rb
38
- homepage: http://makersacademy.com
39
- licenses: []
54
+ - bin/unixoid-debug
55
+ - challenge_spec.rb
56
+ - lib/unixoid.rb
57
+ - lib/unixoid/challenge.rb
58
+ - lib/unixoid/challenge_result.rb
59
+ - lib/unixoid/colorize.rb
60
+ - lib/unixoid/controller.rb
61
+ - lib/unixoid/git.rb
62
+ - lib/unixoid/github.rb
63
+ - lib/unixoid/runner.rb
64
+ homepage: http://github.com/makersacademy/unixoid-challenge
65
+ licenses:
66
+ - MIT
40
67
  metadata: {}
41
68
  post_install_message:
42
69
  rdoc_options: []
@@ -1,18 +0,0 @@
1
- class UnixoidChallenge
2
- def self.run
3
- puts "Running the Unixoid Challenge Assessor ..."
4
- File.write 'unixoid_spec.rb', File.readlines(File.join(File.dirname(__FILE__), '..','spec','unixoid_spec.rb')).join
5
- `rspec unixoid_spec.rb > unixoid_results.txt`
6
- puts 'Please enter your github user name:'
7
- username = gets.chomp
8
- curl = %Q{curl -u #{username} https://api.github.com/user/repos -d '{"name":"unixoid_submission"}'}
9
- %x[#{curl}]
10
- `git init`
11
- `git add unixoid_results.txt`
12
- `git commit -am 'unixoid submission'`
13
- add_remote = "git remote add origin git@github.com:#{username}/unixoid_submission.git"
14
- %x[#{add_remote}]
15
- `git push -f origin master`
16
- puts "Completed Submission!"
17
- end
18
- end