This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/lib/life_game_viewer/view/life_table_model.rb b/lib/life_game_viewer/view/life_table_model.rb | |
| index 0ee2966..6cbcba1 100644 | |
| --- a/lib/life_game_viewer/view/life_table_model.rb | |
| +++ b/lib/life_game_viewer/view/life_table_model.rb | |
| @@ -3,15 +3,26 @@ require 'java' | |
| java_import javax.swing.table.AbstractTableModel | |
| java_import javax.swing.JOptionPane | |
| +require 'forwardable' | |
| + |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| # Creates a new Rails project configured to use | |
| # rspec instead of TestUnit. | |
| # | |
| # - Keith Bennett, Github/Twitter: keithrbennett | |
| ADD_RSPEC_COMMAND = %{ | |
| group :development, :test do |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # A Rails builder that will create projects using RSpec instead of TestUnit. | |
| # Invoke as: rails new my_project builder=rspec-rails-builder.rb | |
| class AppBuilder < Rails::AppBuilder | |
| # Override superclass test method to do rspec stuff. | |
| def test | |
| puts('Adding rspec to Gemfile.') | |
| append_rspec_to_gemfile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| >rails new myapp -m https://raw.github.com/RailsApps/rails-composer/master/composer.rb -T | |
| create | |
| create README.rdoc | |
| create Rakefile | |
| create config.ru | |
| create .gitignore | |
| create Gemfile | |
| create app | |
| create app/assets/images/rails.png |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def list_candidates(extensions, command_name) | |
| dirs = ENV['PATH'].split(File::PATH_SEPARATOR) | |
| filespecs = [] | |
| dirs.each do |dir| | |
| filespec_stem = File.join(dir, command_name) | |
| extensions.each do |extension| | |
| filespecs << (filespec_stem + extension) | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| LINE_SEPARATOR = '-' * 79 | |
| # Currying - using a function that takes n parameters, | |
| # create a new function that call it, providing some of those | |
| # parameters so that it requires < n parameters | |
| # (e.g. double for mult, square for power below): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| =begin | |
| The "Class Variable" Method in class GuidProvider1 (the "@@" notation) is | |
| simpler to use, but violates the principle that the object that owns a | |
| variable is the only one who can directly read or modify it. That is, there | |
| is no privacy or protection, in that there is no way the instances can be | |
| prevented from reading and writing to the variable (for example, the 'next' | |
| instance method does both). | |
| In contrast, the "Class Instance Variable" single @ notation as shown in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def prime_numbers(upper_bound) | |
| return [] if upper_bound < 2 | |
| primes = [2] | |
| 3.upto(upper_bound) do |n| | |
| is_prime = !!! primes.detect { |prime| mult_of?(n, prime) } | |
| primes << n if is_prime | |
| end | |
| return primes | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # JRuby 1.7.1 on Mac OS X, java version "1.6.0_37" | |
| >rvm 1.9 | |
| >ruby -e "require 'resolv'; puts Resolv.getaddress 'cnn.com'" | |
| 157.166.255.19 | |
| >rvm jruby # 1.7.1 | |
| >ruby -e "require 'resolv'; puts Resolv.getaddress 'cnn.com'" | |
| Resolv::ResolvError: no address for cnn.com | |
| getaddress at /Users/keithb/.rvm/rubies/jruby-1.7.1/lib/ruby/1.9/resolv.rb:93 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Illustrates the overhead of the JRuby <--> Java bridge | |
| # parameter and return value type conversions, and the | |
| # dramatic performance improvement that can be had by | |
| # specifying the Java overload using java_method. | |
| require 'java' | |
| require 'benchmark' | |
| ITERATION_COUNT = ARGV.empty? ? 100_000 : ARGV.first.to_i | |
| JMath = java.lang.Math |