Skip to content

Instantly share code, notes, and snippets.

@tal
tal / log.rb
Created May 10, 2011 15:13
A fast and easy way to make logs
module Log
LOGS = Hash.new {|h,k| h[k] = Logger.new("log/#{k}.log")}
extend self
def method_missing name
LOGS[name]
end
end
@tal
tal / _model_ext.rb
Created April 26, 2011 18:31
How to allow sequel models to be passed into filters
class Sequel::Model
def sql_literal(dataset=nil)
self.pk
end
end
var keyCodes = {
backspace: 8,
tab: 9,
enter: 13,
escape: 27,
left: 37,
up: 38,
right: 39,
down: 40,
delete: 46,
>> m = Match.first
=> #<Match _id: 4d9bce2458f68fbb67000001, user_ids: [1, 2], _id: BSON::ObjectId('4d9bce2458f68fbb67000001'), _type: nil>
>> m.players.create(:user_id => 1)
NoMethodError: undefined method `name' for nil:NilClass
<a href="#" class="button h64" id="buy_package_1234">
<div class="left bg"></div>
<div class="right bg"></div>
<span class="text">Buy</span>
</a>
@tal
tal / .bashrc
Created January 25, 2011 18:40
Definition of the gg alias.
function gg { freyr $@ --config-file="/web/Freyrfile" --ignore-local --namespace=gg; }
require 'benchmark'
arr = [*0..99999]
num = 100
Benchmark.bmbm do |x|
x.report("sym#to_proc") do
num.times do
arr.each(&:to_i)
end
end
@tal
tal / gist:739427
Created December 13, 2010 19:06
Stack class with built in min value
class Stack
def initialize
@main = []
@min = []
end
def push val
@main << val
server:
:start: "merb -p 80{{instance%2}}"
:instances: 40
:environment:
merb_env: production
workers:
:start: rake resque:work
:instances: 1
:arg0: '*'
module QikLog
def self.method_missing meth
unless logger = instance_variable_get(:"@#{meth}")
logger = Logger.new(File.join('log',"#{meth}.log"))
instance_variable_set(:"@#{meth}", logger)
end
logger
end
end