View gist:9073d274220e8684047a
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 WeightedSampler | |
def initialize(items) | |
@items = normalize(items) | |
end | |
def sample(num = nil) | |
return get_sample unless num | |
Array.new(num) { get_sample } | |
end |
View gist:93993
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
[#|2009-04-12T14:19:19.480+0200|INFO|glassfish|null|_ThreadID=10;_ThreadName=Thread-1;|Listening on port 3000|#] | |
[#|2009-04-12T14:19:19.539+0200|INFO|glassfish|javax.enterprise.system.tools.admin|_ThreadID=10;_ThreadName=Thread-1;|Admin Console Adapter: context root: /_____admingui|#] | |
[#|2009-04-12T14:19:19.585+0200|INFO|glassfish|null|_ThreadID=10;_ThreadName=Thread-1;|The Admin Console Application is not yet installed.|#] | |
[#|2009-04-12T14:19:19.586+0200|INFO|glassfish|null|_ThreadID=10;_ThreadName=Thread-1;|Admin Console Adapter: context root: /_____admingui|#] | |
[#|2009-04-12T14:19:20.262+0200|INFO|glassfish|javax.enterprise.system.core|_ThreadID=10;_ThreadName=Thread-1;|Loading application test-merb at /|#] |
View gist:213835
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
>> 1.duplicable? | |
=> false | |
>> 1.dup | |
TypeError: can't dup Fixnum | |
from (irb):10:in `dup' | |
from (irb):10 | |
>> "aloha".duplicable? | |
=> true |
View gist:225533
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
Factory.define :user do |user| | |
user.fullname "Michael Bensoussan" | |
user.children {|child| [child.association(:child1), child.association(:child2)]} | |
end |
View gist:226507
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
list = (Date.parse("2009-10-01") .. Date.parse("2009-10-30")).inject([]) do |sum, date| | |
if [1, 2].include? date.cwday #monday or tueday | |
sum << date | |
end | |
sum | |
end |
View gist:228928
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 dup(toto) | |
a = [] | |
toto.each do |b| | |
a << b | |
end | |
a | |
end | |
dup([1,2,3]) |
View gist:238204
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
>> h = Hash.new {raise IndexError } | |
=> {} | |
>> h[:bla] | |
IndexError: IndexError | |
from (irb):39 | |
from (irb):40:in `call' | |
from (irb):40:in `default' | |
from (irb):40:in `[]' | |
from (irb):40 | |
>> h = {} |
View gist:239125
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 unlogged | |
request.env['warden'] = Warden::Proxy.new(request.env, {:default_strategies => [:rememberable, :authenticable],:silence_missing_strategies => true}) | |
end |
View gist:239110
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 logged_as(user) | |
proxy = Warden::Proxy.new(request.env, {:default_strategies => [:rememberable, :authenticable], :silence_missing_strategies => true}) | |
proxy.set_user(user, :store => true, :scope => :user) | |
request.env['warden'] = proxy | |
end |
View gist:250494
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
function record(channel) { | |
console.log("recording channel: " + channel); | |
} | |
var surf = fun( | |
[{genre: 'football', showTitle: _, repeat: _, station: _}, $, record], | |
[{genre: 'comedy', showTitle: _, repeat: false, station: _}, $, record], | |
[{genre: 'crime', showTitle: 'Cops', repeat: _, station: _}, $, record], | |
[{genre: _, showTitle: _, repeat: _, station: _}, $, function () {}] | |
); |
OlderNewer