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
static unsigned long POWERS_OF_TWO[] = { | |
1,2,4,8,16,32,64,128, | |
256,512,1024,2048,4096,8192,16384,32768, | |
65536,131072,262144,524288,1048576,2097152,4194304,8388608, | |
16777216,33554432,67108864,134217728,268435456,536870912,1073741824,2147483648LL | |
// 2147483648 = 2**31 isn't handled well by gcc, should explicitly go with 2147483648LL | |
}; | |
// for testing and debug output purposes |
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 Enumerable | |
def my_inject(default=0) | |
self.each do |i| | |
default = yield(default, i) | |
end | |
default | |
end | |
end | |
puts [1, 2, 3].my_inject { |a, b| a + b }.inspect |
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 Validator | |
validate: (questionId) -> | |
self = this | |
question = $("##{questionId}") | |
questionType = question.attr('type') | |
method = toCamelCase("validate_#{questionType}") | |
if @[method] | |
@[method](questionId) | |
else | |
console.log "missing validator for #{}" |
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 singleton(cls): | |
instances = {} | |
def getinstance(): | |
if cls not in instances: | |
instances[cls] = cls() | |
return instances[cls] | |
return getinstance |
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 Object | |
def not | |
Not.new self | |
end | |
class Not | |
def initialize(original) | |
@original = original | |
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
def dfs(g, start): | |
stack, enqueued = [(None, start)], set([start]) | |
while stack: | |
parent, n = stack.pop() | |
yield parent, n | |
new = set(g.get(n, set())) - enqueued | |
enqueued |= new | |
stack.extend([(n, child) for child in new]) |
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
ln -s /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl |
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
fn map<T, U>(list: &[T], f: &fn(T) -> U) -> ~[U] { | |
let mut acc = ~[]; | |
for i in list.iter() { | |
acc.push(f(i)); | |
} | |
acc | |
} | |
fn print_elems(list: &[int]) { | |
for i in list.iter() { println(fmt!("%?", i)); } |
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
extern mod std; | |
use std::cmp::{TotalEq, Eq}; | |
pub struct Foo { | |
priv bar: int | |
} | |
impl TotalEq for Foo { | |
fn equals(&self, other: &Foo) -> bool { | |
self.bar == other.bar |
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
#!/bin/bash | |
# node.js using PPA (for statsd) | |
sudo apt-get install -y python-software-properties | |
sudo apt-add-repository ppa:chris-lea/node.js | |
sudo apt-get update | |
sudo apt-get install -y nodejs npm | |
# Install git to get statsd | |
sudo apt-get install -y git |
OlderNewer