Skip to content

Instantly share code, notes, and snippets.

View louismullie's full-sized avatar

L louismullie

View GitHub Profile
@mislav
mislav / gist:17371
Created October 17, 2008 07:42
haml2erb
class ErbEngine < Haml::Engine
def push_script(text, preserve_script, in_tag = false, preserve_tag = false,
escape_html = false, nuke_inner_whitespace = false)
push_text "<%= #{text.strip} %>"
end
def push_silent(text, can_suppress = false)
push_text "<% #{text.strip} %>"
end
end
@gus
gus / index.txt
Created November 30, 2009 21:55 — forked from toothrot/index.txt
Ruby/Clojure analogs
For each Ruby module/class, we have Ruby methods on the left and the equivalent
Clojure functions and/or relevant notes are on the right.
For clojure functions, symbols indicate existing method definitions, in the
clojure namespace if none is explicitly given. clojure.contrib.*/* functions can
be obtained from http://github.com/kevinoneill/clojure-contrib/tree/master,
ruby-to-clojure.*/* functions can be obtained from the source files in this
gist.
If no method symbol is given, we use the following notation:
@endolith
endolith / frequency_estimator.py
Last active July 15, 2024 21:25
Frequency estimation methods in Python
from __future__ import division
from numpy.fft import rfft
from numpy import argmax, mean, diff, log, nonzero
from scipy.signal import blackmanharris, correlate
from time import time
import sys
try:
import soundfile as sf
except ImportError:
from scikits.audiolab import flacread
@teepark
teepark / btree.py
Created September 9, 2010 22:45
a pure-python B tree and B+ tree implementation
import bisect
import itertools
import operator
class _BNode(object):
__slots__ = ["tree", "contents", "children"]
def __init__(self, tree, contents=None, children=None):
self.tree = tree
@geoffgarside
geoffgarside / gist:747242
Created December 19, 2010 10:14
Ruby function, calculates the shannon entropy for a given word
def word_entropy(word)
len = word.chars.count.to_f
log2 = Math.log(2)
counts = word.chars.inject({}) do |h,c|
h[c] = (h[c] || 0) + 1
h
end
counts.inject(0) do |entropy, pair|
@bithive
bithive / totp.rb
Created May 23, 2011 23:19
Generate Google Authenticator codes in Ruby (requires base32 gem)
#!/usr/bin/env ruby
require 'rubygems'
require 'base32'
require 'openssl'
int = 30
now = Time.now.to_i / int
key = Base32.decode File.read('secret.key').strip
@mrrooijen
mrrooijen / deploy.rb
Created June 26, 2011 02:37
Capistrano with Foreman Capfile
# encoding: utf-8
$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
require 'rvm/capistrano'
set :application, "hirefireapp"
set :repository, "git@codeplane.com:meskyanichi/myapp.git"
set :branch, "develop"
set :rvm_ruby_string, "1.9.2"
@kig
kig / workcrew.js
Created September 2, 2011 11:03
WorkCrew - a WebWorker work queue library
/*
WorkCrew - a WebWorker work queue library
Usage:
// Create an 8 worker pool using worker.js.
var crew = new WorkCrew('worker.js', 8);
// Do something whenever a job is completed.
// The result object structure is
@wader
wader / gist:1245074
Created September 27, 2011 13:45
git push post-receive capistrano deploy hook script
#!/bin/bash
# requires that you use "set :deploy_via, :remote_cache" in deploy.rb
while read oldrev newrev ref
do
if [ "$ref" = "refs/heads/master" ] ; then
echo "Master branch pushed, deploying to staging"
# seams to be set to "." for hooks, unset to make things more normal
unset GIT_DIR
# deploy path, where "current", "releases", "shared" etc are
@bellbind
bellbind / dh-usage.js
Created October 21, 2011 07:09
[nodejs][javascript] Diffie-Hellman key exchange by nodejs-0.5
// node.js 0.5 Diffie-Hellman example
var assert = require("assert");
var crypto = require("crypto");
// the prime is shared by everyone
var server = crypto.createDiffieHellman(512);
var prime = server.getPrime();
// sharing secret key on a pair