Skip to content

Instantly share code, notes, and snippets.

inverse = function (f, lower = -100, upper = 100) {
function (y) uniroot((function (x) f(x) - y), lower = lower, upper = upper)[1]
}
cdf = function (f) {
function (upper) integrate(f, 0.01, upper).value
}
f = 0.453 * exp(-1.036x) * sinh(sqrt(2.29x))
@axiak
axiak / x.js
Created April 20, 2012 21:02
x.js
var _ = require('underscore');
config = {
'compiled_cache_dir': '../css/tmp',
'processors': {
'js': 'java -jar YUICompressor.jar {input}',
'coffee': ['coffee -c {input} {output}', 'js'],
'less': ['lessc', 'css']
},
var exec = require('child_process').exec
, fs = require('fs');
var escapeShell = function(cmd) {
return '"'+cmd.replace(/(["\s'$`\\])/g,'\\$1')+'"';
};
"processors": {
"coffee": {"cmd": "coffee -c {input}", "nextExt": "js"},
"js": {"cmd": "cat", "nextExt": "js1"},
"js1": {"cmd": "cat", "nextExt": "js2"},
"js2": {"cmd": "cat", "nextExt": "js3"},
"js3": {"cmd": "cat", "nextExt": "js4"},
"js4": {"cmd": "cat", "nextExt": "js5"},
"js5": {"cmd": "java -Xmx200m -Xms50m -Xincgc -jar testdir/yuicompressor-2.4.7.jar {input} -o {output}", "outputType": "js"}
}
@axiak
axiak / gist:2892539
Created June 8, 2012 00:12
name denormalizer
class NameDenormalizer(object):
def __init__(self, filename=None):
filename = filename or 'names1.1.csv'
lookup = collections.defaultdict(list)
with open(filename) as f:
reader = csv.reader(f)
for line in reader:
matches = set(line)
for match in matches:
@axiak
axiak / vote_weight.py
Created June 14, 2012 20:24
Weight a vote for an object based on a user's previous voting history
from math import sqrt
def confidence_bounds(ups, downs):
#stolen from reddit!
n = ups + downs
if n == 0:
return 0, 0
z = 1.0 #1.0 = 85%, 1.6 = 95%
phat = float(ups) / n
confidence_positive = sqrt(phat+z*z/(2*n)-z*((phat*(1-phat)+z*z/(4*n))/n))/(1+z*z/n)
def my_reverse(a)
if a.empty?
[]
else
last = a.pop()
[last] + my_reverse(a)
end
end
p my_reverse([1, 2, 3])
@axiak
axiak / hmm.rb
Created June 15, 2012 04:00 — forked from offby1/hmm.rb
class String
def my_reverse
reversed = []
self.each_char do |char|
reversed.unshift(char)
end
reversed.join('')
end
end
class String
def incord(x)
(self.ord + x).chr
end
end
p 'a'.incord 2
border-color: #29447E #29447E #1A356E;
color: white;
background-color: #5B74A8;
background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#637BAD), to(#5872A7));
background-image: -moz-linear-gradient(#637BAD, #5872A7);
background-image: -o-linear-gradient(#637BAD, #5872A7);
background-image: linear-gradient(#637BAD, #5872A7);