Skip to content

Instantly share code, notes, and snippets.

@NeMO84
NeMO84 / log
Created January 7, 2011 23:27
the issue seems to be if I put :ids => /\d/ or :constraints=>{:ids => /\d/} then I get a RuntimeError (route set not finalized):
Started POST "/login.xml" for 127.0.0.1 at 2011-01-07 15:17:10 -0800
RuntimeError (route set not finalized):
Rendered /usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.0.1/lib/action_dispatch/middleware/templates/rescues/_trace.erb (2.7ms)
Rendered /usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.0.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (2.6ms)
Rendered /usr/local/lib/ruby/gems/1.9.1/gems/actionpack-3.0.1/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (12.2ms)
@NeMO84
NeMO84 / Activity 1.6.rb
Created January 11, 2011 09:01
Let me know if things can be improved from both a coding perspective and a performance perspective. Thanks!
# Nirmit Patel
MAX_NUMBER = 100
MIN_NUMBER = 1
MAX_NUMBER_OF_GUESSES = 8
computers_number = rand(MAX_NUMBER - MIN_NUMBER + 1) + MIN_NUMBER
puts "Hello player. What is your name?"
name = gets
name = name.chomp
def numeric?(object)
true if Float(object) rescue false
end
def get_user_response(message, validate_is_number = true)
valid = false
input = nil
loop do
puts message
input = gets.chomp
if validate_is_number
array1 = [1, 2, 3, 4]
array2 = %w{peter piper picked peppers}
array3 = []
# You need to write some code in this part
# to make the program output "Success"
array3 = array1.collect{|i| i.to_s}.zip(array2).flatten
if array3 == ['1', 'peter', '2', 'piper', '3', 'picked', '4', 'peppers']
puts "Success"
CONFIRMATIONS = ["y","yes","sure","yup","why not"]
def get_list_of_names
puts "Please enter a list of words (one,two,three...):"
input = gets.chomp.downcase
input.split(",")
end
def sanitize(names_array)
names_array = names_array.uniq
end
@NeMO84
NeMO84 / sqlserver_adapter.rb
Created February 4, 2011 02:39
lib/active_record/connection_adapters/sqlserver_adapter.rb
def primary_key(table_name)
identity_column(table_name).try(:name) || columns(table_name).first.try(:name)
end
class A < ActiveResource::Base ; end
A.site
=> nil
A.format
=> ActiveResource::Formats::XmlFormat
ActiveResource::Base.site = "http://abc123.com/"
=> "http://abc123.com/"
A.site
ActiveResource::Formats::XmlFormat.decode("<a><b></b></a>")
=> {"b"=>nil}
# Is there any way to to change the xml, such that, we could yeild the following: {"b"=>""}
@NeMO84
NeMO84 / gist:875255
Created March 17, 2011 22:27
Remove place holder keys...
{"muxer"=>{"__content__"=>"mp4"}, "filters"=>{"scale_width"=>{"__content__"=>"640"}, "scale_height"=>{"__content__"=>"480"}, "frame_rate"=>{"__content__"=>"30.00"}}, "codecs"=>{"codec"=>[{"name"=>{"__content__"=>"H264"}, "bit_rate"=>{"__content__"=>"1200000"}}, {"name"=>{"__content__"=>"AAC"}, "bit_rate"=>{"__content__"=>"128000"}, "channels"=>{"__content__"=>"2"}}]}}
# I want to convert the above into
{"muxer"=> {"mp4"}, "filters"=> {"scale_width"=> "640", "scale_height"=> "480", "scale_frate_rate"=> "30.00"}, "codecs"=> {"codec"=>[{"name" => "H264", "bit_rate" => "1200000"},{"name" => "AAC","bit_rate" => "128000","channels" => "2"}]}}
# Essentially remove the "__content__" place holders.
@NeMO84
NeMO84 / Rakefile
Created April 11, 2011 23:34
Rakefile fix for gwik's Rakefile running on diff version of rspec
require 'rubygems'
require 'rspec/core/rake_task'
# Make tasks (originally from curb) -----------------------------------------------------
MAKECMD = ENV['MAKE_CMD'] || 'make'
MAKEOPTS = ENV['MAKE_OPTS'] || ''
FFMPEG_SO = "ext/FFMPEG_core.#{Config::MAKEFILE_CONFIG['DLEXT']}"
file 'ext/Makefile' => 'ext/extconf.rb' do