Skip to content

Instantly share code, notes, and snippets.

Avatar

Michael Bensoussan mickey

View GitHub Profile
@mickey
mickey / gist:9073d274220e8684047a
Created Nov 28, 2014
WeightedSampler -> Randoms with weight
View gist:9073d274220e8684047a
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
[#|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
>> 1.duplicable?
=> false
>> 1.dup
TypeError: can't dup Fixnum
from (irb):10:in `dup'
from (irb):10
>> "aloha".duplicable?
=> true
View gist:225533
Factory.define :user do |user|
user.fullname "Michael Bensoussan"
user.children {|child| [child.association(:child1), child.association(:child2)]}
end
View gist:226507
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
def dup(toto)
a = []
toto.each do |b|
a << b
end
a
end
dup([1,2,3])
View gist:238204
>> 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
def unlogged
request.env['warden'] = Warden::Proxy.new(request.env, {:default_strategies => [:rememberable, :authenticable],:silence_missing_strategies => true})
end
View gist:239110
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
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 () {}]
);