Skip to content

Instantly share code, notes, and snippets.

@jbgo
jbgo / time.js
Created March 8, 2011 18:05
quick and dirty way to check performance of a javascript function in the console
function time(func, repeats) {
var t0 = Date.now(), t1 = null;
for (var i = 0; i < repeats; ++i) {
func();
}
t1 = Date.now();
return t1 - t0;
}
// example
@jbgo
jbgo / Gemfile
Created April 19, 2011 19:13
An example that uses the Osheet::Cell rowspan attribute
source "http://rubygems.org"
gem 'osheet',
:git => 'git://github.com/jbgo/osheet.git',
:branch => 'cell-index'
@jbgo
jbgo / client.py
Created June 6, 2011 19:24
python bert-rpc client and service to demonstrate data being truncated on large responses
import bertrpc
service = bertrpc.Service('localhost', 9999)
def get_data(how_much=100):
return service.request('call').data.lots(how_much)
@jbgo
jbgo / semicolons-matter.md
Created June 17, 2011 15:05
When using semicolons in JavaScript matters

This fails in Firefox, Chrome, and maybe others.

Copy-and-paste all three lines (at the same time) into a debug console to try it for yourself.

function foo() { /* code goes here */ }
foo() // There is no semi-colon here. Add one to fix there error.
(function() { /* anonymouse function */ })() // bork!
@jbgo
jbgo / README.markdown
Created August 3, 2011 19:38
python dependency graph generator

python dependency graph generator

Generates a dependency graph for a list of installed python packages in the form of a dot file for graphviz.

Usage

python dependency-graph.py installed_package_name ... | dot -Tpng -o dependencies.png
@jbgo
jbgo / calories-per-hour.txt
Created September 15, 2011 04:23
calories burned per hour for various activities
Calories Burned Per Hour for 130 lb. Person in order from least to most
Source: http://www.fruitsandveggiesmorematters.org/?page_id=1793
147 - Housecleaning, light, moderate
177 - Bowling
206 - Walking moderately, 3 mph
235 - Bicycling, leisurely
235 - Hatha yoga
235 - Raking lawn
@jbgo
jbgo / search-replace.md
Created November 22, 2011 17:32
Project-wide search/replace

The basic form is:

ack --type=js -f app/views/ | xargs sed -i '' -e 's/search/replace/'

I use ack to generate list of files on which I want to perform the search/replace, and then sed does the actual work. It helps to run this on a clean working directory so I can use git diff to examine the results and git checkout -- . to undo everything and try again if I screw everything up.

@jbgo
jbgo / .git-completion.bash
Created December 7, 2011 18:28
Bash completion for git branches that (still) sucks
_completion_list() {
cur="${COMP_WORDS[COMP_CWORD]}"
COMPREPLY=( $(compgen -W "$*" -- ${cur}) )
}
_complete_git() {
if [ -d .git ]; then
branches=`git branch | cut -c 3-`
tags=`git tag`
_completion_list $branches $tags
fi
@jbgo
jbgo / decorate.rb
Created February 7, 2012 19:24
Decorate all methods in a module - don't try this at home
module Foo
def foo
puts bar
return 42
end
def what(a, b)
puts "#{bar} = #{a} + #{b}"
return 42
end
@jbgo
jbgo / decorate_module.rb
Created February 8, 2012 23:14
A cleaner way to decorate all methods in a module
module Decorator
def self.decorate(target_klass, include_module, decorator_method)
proxy = Class.new { include include_module }.new
target_klass.class_eval do
include_module.instance_methods.each do |name|
undecorated_method = proxy.method(name)
define_method(name) do |*args, &block|