Skip to content

Instantly share code, notes, and snippets.

View benwoody's full-sized avatar

Ben Woodall benwoody

View GitHub Profile
require 'open-uri'
require 'benchmark'
require 'celluloid'
class Winning
include Celluloid
urls = []
urls << "http://ruby-lang.org"
urls << "http://theplatform.com"
require 'open-uri'
require 'benchmark'
urls = []
urls << "http://ruby-lang.org"
urls << "http://theplatform.com"
urls << "http://reddit.com"
urls << "http://pragprog.com"
urls << "http://railscasts.com"
@benwoody
benwoody / gist:3229905
Created August 1, 2012 19:18
ostruct_couchdb_cloudant_thing
require 'couchrest'
require 'ostruct'
configure do
SiteConfig = OpenStruct.new(
:url_base_db => 'https://USERNAME:[email protected]/',
:db_name => "heyo_mountain"
)
end
@benwoody
benwoody / gist:1400731
Created November 28, 2011 15:13
Snake
board_size, snake_length, snake_positions, snake_vector, fruit_position = 15, 3, [[5,6],[5,5],[5,4]], [1,0], [rand(15), rand(15)] # set game board size, snake starting position, snake starting direction and fruit position
system "stty -icanon -echoke" # set console to non-canonical mode so it doesn't require end of line to get input
loop do # loop infinitely
if ( input = select([$stdin], nil, nil, 0.2) ) then if ( STDIN.getc.chr == "\e" ) then if ( STDIN.getc == ?[) then input = STDIN.getc end end end # get input
if ( input == ?A ) then snake_vector = [0,-1] elsif ( input == ?B ) then snake_vector = [0,1] elsif ( input == ?C ) then snake_vector = [1,0] elsif ( input == ?D ) then snake_vector = [-1,0] end # set snake movement direction based on input
snake_positions = (snake_positions.count < snake_length ? snake_positions.concat([[snake_positions.last[0] + snake_vector[0], snake_positions.last[1] + snake_vector[1]]]) : snake_positions.drop(1).concat([[snake_positions.last[0] + snake_vector[0], snake_pos
@benwoody
benwoody / gist:1182196
Created August 30, 2011 21:58
Alcohol Content finder
#!/usr/bin/env ruby
og = ARGV[0].to_f #first argument
fg = ARGV[1].to_f #second argument
if og or fg == nil
puts "usage: ./peralc.rb \'original gravity' \'final gravity'"
Process.exit
end
@benwoody
benwoody / gist:1057361
Created June 30, 2011 21:52
Ruby Liners
# Reversing a String
(0...(a.length/2)).each{|i| a[i], a[-i-1]=a[-i-1], a[i]}
return a
# Fibonacci Sequence
(0...n).inject([0, 1]) { |p, _| [p[1], p[0] + p[1]] }[0]