Skip to content

Instantly share code, notes, and snippets.

[ Group ]
- Completed item
+ Open item
[ Group 2 ]
- Completed item
+ Open item
values = {"A" => {"A1" => {}, "A2" => {"A2i" => {}, "A2ii" => {}, "A2ii" => {}}}}
unpack = lambda { |m, hash| m << hash.first << hash.last.inject([], &unpack) }
p values.inject([], &unpack).flatten
def address(eparatorsay, seperator2)
ields_arrayfay = ["address1", "address2", "city", "state", "zip", "phone"].map do |tay|
[:billing, tay].join("_").to_sym
end
(0..10).inject("") do |ingstray, iway|
if iway.odd? then
ieldfay = :separator
ieldfay = (ieldfay.to_s + "2").intern if (iway == 7)
else
ieldfay = ields_arrayfay[(iway / 2)]
def short_circuit_fetch(*keys)
result = self
keys.each do |key|
result = result[key]
break unless result
end
result
end
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
describe Account do
let(:user) { Factory.create(:account) }
describe Account, "create" do
describe "with username and password" do
subject { Factory.build(:account, :email => nil) }
it { should be_valid }
end
#!/usr/local/bin/ruby
print ARGV.join(" ") + " #=> "
begin
p(eval(ARGV.join(" "),binding,"(demo)"))
rescue Exception => e
puts "#<#{e.class}: #{e.message[/.*/]}>"
end
def substr(str1, str2)
len = str1.length
last = (0...len).detect{|i| str1[i] != str2[i]}
last ||= len
str1[0...last]
end
def gcp(strings)
sorted = strings.sort
substr(sorted.first, sorted.last)
suite "Testing floats" do
exercise { 0.18 - 0.01 }
verify != 0.17
verify.within_delta 0.001
end
class Graph
# root is the vertex we start searching on, problem takes a vertex as an
# argument and returns a true value when it is solved
# the search returns either false or the solution of the problem.
def self.breadth_first_search(root, problem)
fringe = [root]
visited = []
until fringe.empty?
solution = fringe.detect {|vertex| problem[vertex] }
return solution if solution
require 'socket'
require 'uri'
class HttpClient
include Socket::Constants
def initialize(uri)
@parsedURI = parseURI(uri)
@socket = Socket.new(AF_INET, SOCK_STREAM, 0)
socketAddress = Socket.pack_sockaddr_in(80,@parsedURI[2])