infinity2008 1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 99bbe93e46d8b85c551eae8b71fda032d7027d0e
4
+ data.tar.gz: 5ab3a7d02e0bd89be4e7f00dc3868156219e7882
5
+ SHA512:
6
+ metadata.gz: fb3255e55f05167a4838b889350af013355c59612452f2b01ac154452c8b837f15a3520f97ce5d781e28429cfe4ed6162afb45203e2fd5df4acdbf9c0eb07eee
7
+ data.tar.gz: bf10b6006739ca80fa538a863ee3297f5f02ad7da214269958e500c95fce8fef92fc6e0b6e926a9ff9f78586a94e2f5926e5f1e48f7aed9a0165430c9f2bdc63
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --color
2
+ --format d
3
+ --order rand
4
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.1.1
5
+ - jruby-19mode
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in logmonitor.gemspec
4
+ gemspec
5
+
6
+ group :test do
7
+ gem 'rake'
8
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Alejandro Martinez Ruiz <alex at flawedcode dot org>
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,61 @@
1
+ [![Build Status](https://travis-ci.org/unleashed/infinity2008.svg?branch=master)](https://travis-ci.org/unleashed/infinity2008)
2
+
3
+ # The Infinity 2008 (Klaas Vocal Edit) gem
4
+
5
+ This gem makes Ruby sing with you the [Guru Josh Project's Infinity 2008 (Klaas Vocal Edit)](https://www.youtube.com/watch?v=w9KnuJZkBjg) song through both *STDOUT* and the *SOURCE CODE*.
6
+
7
+ The really nice thing is that the code actually sings the lyrics:
8
+ ```ruby
9
+ class Me < Freak
10
+ key :philosophy
11
+ needs :infinity
12
+
13
+ def infinity(you)
14
+ you.relax! and you.r.time.take_while { |time|
15
+ !you.trust.in? self and time.(goes_by: :naturally)
16
+ } and you.will.find INFINITY
17
+ end
18
+ end
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ You should start the song at the same time than this program with something like this:
24
+
25
+ $ infinity2008 & play infinity2008.mp3
26
+
27
+ Or, if you feel like it, watch the video while the program sings:
28
+
29
+ $ infinity2008 --video
30
+
31
+ A much more dense and bare version of the same code suitable for posters or shirts is:
32
+
33
+ $ infinity2008-dense
34
+
35
+ The 'default' non-dense version is more readable, includes support for opening the video and a bit of extra boiler-plate related to code encapsulation.
36
+
37
+ ## Motivation
38
+
39
+ In May 2013 I was listening to Infinity 2008 in a summer hits remember session when I thought that it would be a fun exercise to show how Ruby expressiveness and terseness could be leveraged to write a small program loosely based on the lyrics of the song. The idea was to make it _sing_ both in the console output and specially in the code itself, aiming at making it small enough (even if dense) to print it on a shirt with code highlighting.
40
+
41
+ Actually printing it on a shirt is problematic because the letters end up being pretty small and you'd need a not too wide fixed font, but I encourage you to find a solution for that (and sending me a PR and a couple of those kick-ass shirts!)
42
+
43
+ ## Generating the gem
44
+
45
+ Both bundler and rspec are required to build the gem:
46
+
47
+ $ gem install bundler rspec
48
+
49
+ Run rake -T to see available tasks. The gem can be built with:
50
+
51
+ $ rake build
52
+
53
+ Or, if you want to make sure everything works correctly:
54
+
55
+ $ bundle exec rake build
56
+
57
+ ## Installation
58
+
59
+ After generating the gem, install it using:
60
+
61
+ $ gem install pkg/infinity2008-*.gem
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ ENV['gem_push'] = 'false'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task :default => :spec
data/bin/infinity2008 ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+ $: << File.expand_path('../../lib', __FILE__)
3
+ require 'infinity2008'
4
+
5
+ def open_cmd
6
+ case RbConfig::CONFIG['host_os']
7
+ when /darwin/i
8
+ { open: 'open', null: '/dev/null' }
9
+ when /linux|bsd/i
10
+ { open: 'xdg-open', null: '/dev/null' }
11
+ when /mswin|mingw|cygwin|/i
12
+ { open: 'start', null: 'nul' }
13
+ else
14
+ raise
15
+ end
16
+ end
17
+
18
+ def video(url)
19
+ cmd = open_cmd
20
+ `#{cmd[:open]} #{url} > #{cmd[:null]} 2>&1`
21
+ sleep 2
22
+ rescue
23
+ nil
24
+ end
25
+
26
+ video Infinity2008::Song::URL if ARGV.include? '--video'
27
+ Infinity2008::Song.sing
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+ INFINITY = 2.times.map { :infinity } * ', '
3
+
4
+ class Freak; { key: ",\n", needs: " " }.each { |m, s|
5
+ (class << self; self; end).send :define_method, m do |arg|
6
+ define_method m do "#{m}#{s}#{arg}" end end } end
7
+
8
+ class You
9
+ { INFINITY => lambda { puts "... #{Float::INFINITY}!" }, relax!: lambda {
10
+ puts; true }, time: lambda { [lambda { |_| print '.'; sleep 1 }].cycle }
11
+ }.each { |m, l| define_method(m) { print "#{m} "; l.call } }; def in? o
12
+ (@t ||= ([false] * 188).each).next rescue (puts " trust in #{o.class}"
13
+ true) end; def method_missing(m, *args); m == :find ? send(*args) : self
14
+ end end
15
+
16
+ class Me < Freak
17
+ key :philosophy; needs :infinity; def infinity(you)
18
+ you.relax! and you.r.time.take_while { |time| !you.trust.in? self and
19
+ time.(goes_by: :naturally) } and you.will.find INFINITY
20
+ end end
21
+
22
+ me = Me.new; puts "Here's my #{me.key}\n\nA #{me.class.superclass} like" \
23
+ " #{me.class},\njust #{me.needs}\n"; me.send :infinity, You.new
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'infinity2008'
7
+ spec.version = '1.0'
8
+ spec.authors = ["Alejandro Martinez Ruiz"]
9
+ spec.email = ['alex@flawedcode.org']
10
+ spec.description = %q{This gem makes Ruby sing along with you the Guru Project's Infinity 2008 (Klaas Vocal Edit) hit}
11
+ spec.summary = %q{The Guru Project's Infinity 2008 (Klaas Vocal Edit) gem}
12
+ spec.homepage = "http://github.com/unleashed/infinity2008"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.3"
21
+ spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "rspec"
23
+ end
@@ -0,0 +1,60 @@
1
+ module Infinity2008
2
+ INFINITY = 2.times.map { :infinity } * ', '
3
+
4
+ class Freak
5
+ { key: ",\n", needs: " " }.each do |m, s|
6
+ (class << self; self; end).send :define_method, m do |arg|
7
+ #class_eval { define_method(m) { "#{m}#{s}#{arg}" } }
8
+ define_method(m) { "#{m}#{s}#{arg}" }
9
+ end
10
+ end
11
+
12
+ def self.to_s
13
+ super.split(':').last
14
+ end
15
+ end
16
+
17
+ class You
18
+ { INFINITY => lambda { puts "... #{Float::INFINITY}!" },
19
+ relax!: lambda { puts; true },
20
+ time: lambda do
21
+ [lambda { |_| print '.'; sleep 1 }].cycle
22
+ end
23
+ }.each do |m, l|
24
+ define_method(m) { print "#{m} "; l.call }
25
+ end
26
+
27
+ def in?(o)
28
+ (@t ||= ([false] * Song::Duration).each).next
29
+ rescue
30
+ true.tap { puts " trust in #{o.class}" }
31
+ end
32
+
33
+ def method_missing(m, *args)
34
+ m == :find ? send(*args) : self
35
+ end
36
+ end
37
+
38
+ class Me < Freak
39
+ key :philosophy
40
+ needs :infinity
41
+
42
+ def infinity(you)
43
+ you.relax! and you.r.time.take_while { |time|
44
+ !you.trust.in? self and time.(goes_by: :naturally)
45
+ } and you.will.find INFINITY
46
+ end
47
+ end
48
+
49
+ module Song
50
+ Duration = 188
51
+ URL = 'https://www.youtube.com/watch?v=w9KnuJZkBjg'
52
+
53
+ def self.sing
54
+ me = Me.new
55
+ puts "Here's my #{me.key}\n\nA #{me.class.superclass} like" \
56
+ " #{me.class},\njust #{me.needs}\n"
57
+ me.send :infinity, You.new
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,13 @@
1
+ module Infinity2008
2
+ RSpec.describe Freak do
3
+ subject { Freak }
4
+
5
+ it 'has a key' do
6
+ expect(subject).to respond_to(:key)
7
+ end
8
+
9
+ it 'has needs' do
10
+ expect(subject).to respond_to(:needs)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,37 @@
1
+ module Infinity2008
2
+ RSpec.describe 'Integration' do
3
+ let(:me) { Me }
4
+ let(:you) { You }
5
+ let(:duration) { Song::Duration }
6
+
7
+ it 'will take time' do
8
+ slept = 0
9
+ allow_any_instance_of(Kernel).to receive(:sleep) do |_, secs|
10
+ slept += secs
11
+ secs
12
+ end
13
+ me.new.infinity(you.new)
14
+ expect(slept).to be >= duration
15
+ end
16
+
17
+ context You do
18
+ let(:infinity) { INFINITY }
19
+
20
+ subject do
21
+ you.new.tap do |you|
22
+ duration.times { you.trust.in? me }
23
+ end
24
+ end
25
+
26
+ it 'will find infinity' do
27
+ expect(subject).to receive(:find).with(infinity)
28
+ me.new.infinity subject
29
+ end
30
+
31
+ it 'will receive infinity' do
32
+ expect(subject).to receive(infinity)
33
+ me.new.infinity subject
34
+ end
35
+ end
36
+ end
37
+ end
data/spec/me_spec.rb ADDED
@@ -0,0 +1,17 @@
1
+ module Infinity2008
2
+ RSpec.describe Me do
3
+ let(:freak) { Freak }
4
+
5
+ it 'is a freak' do
6
+ expect(subject).to be_a(freak)
7
+ end
8
+
9
+ it 'has philosophy as key' do
10
+ expect(subject.key).to match(/\bphilosophy\b/)
11
+ end
12
+
13
+ it 'needs infinity' do
14
+ expect(subject.needs).to match(/\binfinity\b/)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,92 @@
1
+ $LOAD_PATH << File.expand_path('../lib', __FILE__)
2
+
3
+ # This file was generated by the `rspec --init` command. Conventionally, all
4
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
5
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
6
+ # file to always be loaded, without a need to explicitly require it in any files.
7
+ #
8
+ # Given that it is always loaded, you are encouraged to keep this file as
9
+ # light-weight as possible. Requiring heavyweight dependencies from this file
10
+ # will add to the boot time of your test suite on EVERY test run, even for an
11
+ # individual file that may not need all of that loaded. Instead, make a
12
+ # separate helper file that requires this one and then use it only in the specs
13
+ # that actually need it.
14
+ #
15
+ # The `.rspec` file also contains a few flags that are not defaults but that
16
+ # users commonly want.
17
+ #
18
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
+
20
+ require 'stringio'
21
+ require 'infinity2008'
22
+
23
+ RSpec.configure do |config|
24
+ orig_stdout = $stdout
25
+ config.before :all do
26
+ $stdout = StringIO.new
27
+ end
28
+ config.after :all do
29
+ $stdout = orig_stdout
30
+ end
31
+
32
+ # The settings below are suggested to provide a good initial experience
33
+ # with RSpec, but feel free to customize to your heart's content.
34
+ =begin
35
+ # These two settings work together to allow you to limit a spec run
36
+ # to individual examples or groups you care about by tagging them with
37
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
38
+ # get run.
39
+ config.filter_run :focus
40
+ config.run_all_when_everything_filtered = true
41
+
42
+ # Many RSpec users commonly either run the entire suite or an individual
43
+ # file, and it's useful to allow more verbose output when running an
44
+ # individual spec file.
45
+ if config.files_to_run.one?
46
+ # Use the documentation formatter for detailed output,
47
+ # unless a formatter has already been configured
48
+ # (e.g. via a command-line flag).
49
+ config.default_formatter = 'doc'
50
+ end
51
+
52
+ # Print the 10 slowest examples and example groups at the
53
+ # end of the spec run, to help surface which specs are running
54
+ # particularly slow.
55
+ config.profile_examples = 10
56
+
57
+ # Run specs in random order to surface order dependencies. If you find an
58
+ # order dependency and want to debug it, you can fix the order by providing
59
+ # the seed, which is printed after each run.
60
+ # --seed 1234
61
+ config.order = :random
62
+
63
+ # Seed global randomization in this process using the `--seed` CLI option.
64
+ # Setting this allows you to use `--seed` to deterministically reproduce
65
+ # test failures related to randomization by passing the same `--seed` value
66
+ # as the one that triggered the failure.
67
+ Kernel.srand config.seed
68
+
69
+ # rspec-expectations config goes here. You can use an alternate
70
+ # assertion/expectation library such as wrong or the stdlib/minitest
71
+ # assertions if you prefer.
72
+ config.expect_with :rspec do |expectations|
73
+ # Enable only the newer, non-monkey-patching expect syntax.
74
+ # For more details, see:
75
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
76
+ expectations.syntax = :expect
77
+ end
78
+
79
+ # rspec-mocks config goes here. You can use an alternate test double
80
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
81
+ config.mock_with :rspec do |mocks|
82
+ # Enable only the newer, non-monkey-patching expect syntax.
83
+ # For more details, see:
84
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
85
+ mocks.syntax = :expect
86
+
87
+ # Prevents you from mocking or stubbing a method that does not exist on
88
+ # a real object. This is generally recommended.
89
+ mocks.verify_partial_doubles = true
90
+ end
91
+ =end
92
+ end
data/spec/you_spec.rb ADDED
@@ -0,0 +1,39 @@
1
+ module Infinity2008
2
+ RSpec.describe You do
3
+ let(:me) { Me }
4
+ let(:duration) { Song::Duration }
5
+
6
+ it 'can relax!' do
7
+ expect { subject.relax! }.not_to raise_error
8
+ end
9
+
10
+ it 'can take his time' do
11
+ expect { subject.time }.not_to raise_error
12
+ end
13
+
14
+ context 'trust' do
15
+ it 'can trust' do
16
+ expect { subject.trust }.not_to raise_error
17
+ end
18
+
19
+ it 'can trust or not in someone' do
20
+ expect(subject.trust).to respond_to(:in?)
21
+ end
22
+
23
+ it 'does not trust in me' do
24
+ expect(subject.trust.in? me).to be(false)
25
+ end
26
+
27
+ it 'after some time does not trust in me' do
28
+ (duration - 1).times do
29
+ expect(subject.trust.in? me).to be(false)
30
+ end
31
+ end
32
+
33
+ it 'after some more time trusts in me' do
34
+ duration.times { subject.trust.in? me }
35
+ expect(subject.trust.in? me).to be(true)
36
+ end
37
+ end
38
+ end
39
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: infinity2008
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ platform: ruby
6
+ authors:
7
+ - Alejandro Martinez Ruiz
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-10 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: This gem makes Ruby sing along with you the Guru Project's Infinity 2008
56
+ (Klaas Vocal Edit) hit
57
+ email:
58
+ - alex@flawedcode.org
59
+ executables:
60
+ - infinity2008
61
+ - infinity2008-dense
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - ".rspec"
66
+ - ".travis.yml"
67
+ - Gemfile
68
+ - LICENSE
69
+ - README.md
70
+ - Rakefile
71
+ - bin/infinity2008
72
+ - bin/infinity2008-dense
73
+ - infinity2008.gemspec
74
+ - lib/infinity2008.rb
75
+ - spec/freak_spec.rb
76
+ - spec/integration_spec.rb
77
+ - spec/me_spec.rb
78
+ - spec/spec_helper.rb
79
+ - spec/you_spec.rb
80
+ homepage: http://github.com/unleashed/infinity2008
81
+ licenses:
82
+ - MIT
83
+ metadata: {}
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 2.2.2
101
+ signing_key:
102
+ specification_version: 4
103
+ summary: The Guru Project's Infinity 2008 (Klaas Vocal Edit) gem
104
+ test_files:
105
+ - spec/freak_spec.rb
106
+ - spec/integration_spec.rb
107
+ - spec/me_spec.rb
108
+ - spec/spec_helper.rb
109
+ - spec/you_spec.rb