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
| [ Group ] | |
| - Completed item | |
| + Open item | |
| [ Group 2 ] | |
| - Completed item | |
| + Open item |
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
| values = {"A" => {"A1" => {}, "A2" => {"A2i" => {}, "A2ii" => {}, "A2ii" => {}}}} | |
| unpack = lambda { |m, hash| m << hash.first << hash.last.inject([], &unpack) } | |
| p values.inject([], &unpack).flatten |
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 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)] |
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 short_circuit_fetch(*keys) | |
| result = self | |
| keys.each do |key| | |
| result = result[key] | |
| break unless result | |
| end | |
| result | |
| 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
| 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 |
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/local/bin/ruby | |
| print ARGV.join(" ") + " #=> " | |
| begin | |
| p(eval(ARGV.join(" "),binding,"(demo)")) | |
| rescue Exception => e | |
| puts "#<#{e.class}: #{e.message[/.*/]}>" | |
| 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
| 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) |
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
| suite "Testing floats" do | |
| exercise { 0.18 - 0.01 } | |
| verify != 0.17 | |
| verify.within_delta 0.001 | |
| 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
| 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 |
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
| 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]) |