D, Y = 8, 0
8===D-- ( Y )
This file contains 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
module PostFile | |
def post_file(url, file_path, field_name = 'file') | |
file_name = File.basename(file_path) | |
boundary = "AaB03x" | |
data = <<EOF | |
--#{boundary}\r | |
Content-Disposition: form-data; name="#{field_name}"; filename="#{file_name}"\r | |
\r | |
#{File.read(file_path)}\r | |
--#{boundary}--\r |
This file contains 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 self.underscore_hash(hash) | |
hash.inject({}) do |underscored, (key, value)| | |
value = underscore_hash(value) if value.is_a?(Hash) | |
value = value.map { |v| underscore_hash(v) } if value.is_a?(Array) | |
underscored[key.underscore] = value | |
underscored | |
end | |
end |
This file contains 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
irb(main):034:0> D, Y = 8, 0 | |
=> [8, 0] | |
irb(main):035:0> 8===D-- ( Y ) | |
=> true |
This file contains 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
/* yes - output a string repeatedly until killed | |
Copyright (C) 1991-1997, 1999-2004, 2007-2011 Free Software Foundation, Inc. | |
This program is free software: you can redistribute it and/or modify | |
it under the terms of the GNU General Public License as published by | |
the Free Software Foundation, either version 3 of the License, or | |
(at your option) any later version. | |
This program is distributed in the hope that it will be useful, | |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
This file contains 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 'benchmark' | |
Benchmark.bmbm do |b| | |
b.report("single") do | |
10_000.times do | |
'some string' | |
end | |
end | |
b.report("double") do | |
10_000.times do | |
"some string" |
This file contains 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 'benchmark' | |
require 'set' | |
some_numbers = [] | |
1_000_000.times do | |
num = rand(100_000) | |
rand(5).times do | |
some_numbers << {:id => num} | |
end |
This file contains 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
# from http://moonbase.rydia.net/mental/blog/programming/eavesdropping-on-expressions | |
# For debugging and getting a puts in there, tap is nice | |
def blah | |
@things.map { |x| | |
x.length | |
}.inject( 0 ) { |a, b| | |
a + b | |
} | |
end |
This file contains 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 Array | |
def powerset | |
inject([[]]){ |c,y| | |
c.inject([]) {|r,i| | |
r+=[i,i+[y]] | |
} | |
} | |
end | |
end |
This file contains 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
# = delegate -- Support for the Delegation Pattern | |
# | |
# Documentation by James Edward Gray II and Gavin Sinclair | |
# | |
# == Introduction | |
# | |
# This library provides three different ways to delegate method calls to an | |
# object. The easiest to use is SimpleDelegator. Pass an object to the | |
# constructor and all methods supported by the object will be delegated. This | |
# object can be changed later. |