aoc 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 199b5f89d04bfb1cdac22dad9ec2d117674a22384f7b38d5832484d97be3447b
4
+ data.tar.gz: 4a90c8df854aa70ef42fdf8b01f6963526d5d409e61f7ee4eacaf33b35487449
5
+ SHA512:
6
+ metadata.gz: 3686a308fddc9dec9542de0e9d9f9e351ccee9a883cb6da7146c3ffcc26d47d1dc7effb432cecffb7af1db54125e90d0e6ecf4cc48ab13be69ffb56763073ee1
7
+ data.tar.gz: 4bd6b59ed9f8af49569f1f64d29928be36c91c72b4b486dcced6754ff2ada446fe3c302a1c60a448435f3974bfbb984b055ec65ca8e01f3fb39ee110c0601030
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in aoc.gemspec
6
+ gemspec
@@ -0,0 +1,28 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ aoc (0.1.0)
5
+ nokogiri (~> 1.6, >= 1.6.8)
6
+ thor (~> 0.19.1)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ mini_portile2 (2.3.0)
12
+ minitest (5.8.5)
13
+ nokogiri (1.8.5)
14
+ mini_portile2 (~> 2.3.0)
15
+ rake (10.4.2)
16
+ thor (0.19.4)
17
+
18
+ PLATFORMS
19
+ ruby
20
+
21
+ DEPENDENCIES
22
+ aoc!
23
+ bundler (~> 1.17)
24
+ minitest (~> 5.0)
25
+ rake (~> 10.0)
26
+
27
+ BUNDLED WITH
28
+ 1.17.1
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Jonathan Lalande
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,72 @@
1
+ # Aoc
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/aoc`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'aoc'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install aoc
22
+
23
+ ## Usage
24
+
25
+ ### bootstrap
26
+ You can bootstrap an advent of code challenge by using:
27
+ ```
28
+ $ aoc bootstrap
29
+ ```
30
+
31
+ This will create a directory containing today's challenge instructions, input file and a solution.rb file where you can start coding
32
+ your solution.
33
+
34
+ You can also bootstrap a challenge of an other day:
35
+ ```
36
+ $ aoc bootstrap 15 2017
37
+ ```
38
+
39
+ This will create a directory for day 15 of year 2017.
40
+
41
+
42
+ ### fetch
43
+ You can also just output the challenge instruction using fetch:
44
+ ```
45
+ $ aoc fetch
46
+ ```
47
+
48
+ This will print today's challenge instructions.
49
+
50
+ You can also print the input of the challenge:
51
+ ```
52
+ $ aoc fetch --input
53
+ ```
54
+
55
+ Like bootstrap, you can also specifiy a challenge's day and year.
56
+ ```
57
+ $ aoc fetch 5 2016
58
+ ```
59
+
60
+ ## Development
61
+
62
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
63
+
64
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
65
+
66
+ ## Contributing
67
+
68
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/aoc.
69
+
70
+ ## License
71
+
72
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,32 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "aoc/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "aoc"
8
+ spec.version = Aoc::VERSION
9
+ spec.authors = ["Jonathan Lalande"]
10
+ spec.email = ["lalandej.gg@gmail.com"]
11
+
12
+ spec.summary = %q{Advent of Code toolkit}
13
+ spec.description = %q{Advent of Code toolkit to fetch inputs and submit answers efficiently.}
14
+ spec.homepage = "https://github.com/zergov/aoc/"
15
+ spec.license = "MIT"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = "bin"
23
+ spec.executables = ["aoc"]
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.17"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "minitest", "~> 5.0"
29
+
30
+ spec.add_dependency 'thor', '~> 0.19.1'
31
+ spec.add_dependency 'nokogiri', '~> 1.6', '>= 1.6.8'
32
+ end
data/bin/aoc ADDED
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'aoc'
4
+ require 'thor'
5
+ require 'date'
6
+
7
+ class CLI < Thor
8
+ desc "fetch [day] [year]", "fetch and display a challenge description. If no day and year, use today's date."
9
+ method_option :input, :aliases => "-i", :type => :boolean, :default => false, :desc => "only show the input of the challenge."
10
+ def fetch(day = Date.today.day, year = Date.today.year)
11
+ challenge = Aoc::Challenge.new(day, year)
12
+
13
+ begin
14
+ return puts challenge.input if options[:input]
15
+ rescue OpenURI::HTTPError
16
+ return puts "Cannot find the input for your challenge. Make sure your session key is valid."
17
+ end
18
+
19
+ begin
20
+ puts "Fetching: day #{day}, #{year}"
21
+ puts challenge.part1
22
+ puts challenge.part2
23
+ rescue OpenURI::HTTPError
24
+ puts "Cannot find this challenge, make sure it exists."
25
+ end
26
+ end
27
+
28
+ desc "bootstrap [day] [year]", "bootstrap a challenge."
29
+ def bootstrap(day = Date.today.day, year = Date.today.year)
30
+ challenge = Aoc::Challenge.new(day, year)
31
+ puts "Bootstrapping: day #{day}, #{year}"
32
+
33
+ begin
34
+ dir = "day#{day}"
35
+ readme = File.join(dir, "README")
36
+ input = File.join(dir, "input.txt")
37
+ solution = File.join(dir, "solution.rb")
38
+
39
+ Dir.mkdir(dir) unless File.directory?(dir)
40
+
41
+ File.open(readme, "w") do |file|
42
+ file << challenge.part1
43
+ file << "\n"
44
+ file << challenge.part2 if challenge.part2?
45
+ end
46
+
47
+ unless File.exist?(input)
48
+ File.write(input, challenge.input)
49
+ end
50
+
51
+ unless File.exist?(solution)
52
+ File.open(solution, "w") do |file|
53
+ file << Aoc::Templates.solution_file_template
54
+ end
55
+ end
56
+ rescue OpenURI::HTTPError
57
+ puts "Cannot find this challenge, make sure it exists."
58
+ end
59
+ end
60
+ end
61
+
62
+ CLI.start
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "aoc"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,4 @@
1
+ require "aoc/version"
2
+ require 'aoc/challenge'
3
+ require 'aoc/session'
4
+ require 'aoc/templates'
@@ -0,0 +1,43 @@
1
+ require 'nokogiri'
2
+ require 'open-uri'
3
+
4
+ module Aoc
5
+ class Challenge
6
+ def initialize(day, year)
7
+ @day = day
8
+ @year = year
9
+ end
10
+
11
+ def url
12
+ "https://adventofcode.com/#{@year}/day/#{@day}"
13
+ end
14
+
15
+ def part1
16
+ @part1 ||= content.css('article.day-desc').first.text
17
+ end
18
+
19
+ def part2
20
+ if part2?
21
+ @part2 ||= content.css('article.day-desc').last.text
22
+ else
23
+ "Part 2 not unlocked yet"
24
+ end
25
+ end
26
+
27
+ def part2?
28
+ content.css('article.day-desc').count > 1
29
+ end
30
+
31
+ def input
32
+ session = Aoc::Session.get_session
33
+ @input ||= Nokogiri::HTML(open("#{url}/input", "Cookie" => "session=#{session}")).text
34
+ end
35
+
36
+ private
37
+
38
+ def content
39
+ session = Aoc::Session.get_session
40
+ @content ||= Nokogiri::HTML(open(url, "Cookie" => "session=#{session}"))
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,39 @@
1
+ module Aoc
2
+ module Session
3
+ def self.get_session
4
+ return @session if @session
5
+
6
+ if persisted?
7
+ @session = load_session
8
+ else
9
+ @session = ask_for_session
10
+ persist_session
11
+ end
12
+
13
+ @session
14
+ end
15
+
16
+ private
17
+
18
+ def self.ask_for_session
19
+ puts "Enter your session key:"
20
+ STDIN.gets.chomp
21
+ end
22
+
23
+ def self.load_session
24
+ File.read(session_store)
25
+ end
26
+
27
+ def self.persisted?
28
+ File.exist?(session_store)
29
+ end
30
+
31
+ def self.persist_session
32
+ File.write(session_store, @session)
33
+ end
34
+
35
+ def self.session_store
36
+ File.join(Dir.home, ".aoc.session")
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,20 @@
1
+ module Aoc
2
+ module Templates
3
+ def self.solution_file_template
4
+ <<~CODE
5
+ #!/usr/bin/env ruby
6
+
7
+ def part1
8
+ input = File.read('input.txt')
9
+ end
10
+
11
+ def part2
12
+ input = File.read('input.txt')
13
+ end
14
+
15
+ puts "Solution part1: \#{part1}"
16
+ puts "Solution part2: \#{part2}"
17
+ CODE
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ module Aoc
2
+ VERSION = "0.0.0"
3
+ end
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aoc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jonathan Lalande
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-12-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: thor
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.19.1
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.19.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: nokogiri
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.6'
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: 1.6.8
79
+ type: :runtime
80
+ prerelease: false
81
+ version_requirements: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - "~>"
84
+ - !ruby/object:Gem::Version
85
+ version: '1.6'
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: 1.6.8
89
+ description: Advent of Code toolkit to fetch inputs and submit answers efficiently.
90
+ email:
91
+ - lalandej.gg@gmail.com
92
+ executables:
93
+ - aoc
94
+ extensions: []
95
+ extra_rdoc_files: []
96
+ files:
97
+ - ".gitignore"
98
+ - Gemfile
99
+ - Gemfile.lock
100
+ - LICENSE.txt
101
+ - README.md
102
+ - Rakefile
103
+ - aoc.gemspec
104
+ - bin/aoc
105
+ - bin/console
106
+ - bin/setup
107
+ - lib/aoc.rb
108
+ - lib/aoc/challenge.rb
109
+ - lib/aoc/session.rb
110
+ - lib/aoc/templates.rb
111
+ - lib/aoc/version.rb
112
+ homepage: https://github.com/zergov/aoc/
113
+ licenses:
114
+ - MIT
115
+ metadata: {}
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ requirements: []
131
+ rubyforge_project:
132
+ rubygems_version: 2.7.7
133
+ signing_key:
134
+ specification_version: 4
135
+ summary: Advent of Code toolkit
136
+ test_files: []