Skip to content

Instantly share code, notes, and snippets.

@jbgo
jbgo / Gemfile
Created February 15, 2014 19:16
Heroku-style config management with capistrano and chef
gem 'dotenv-rails'
group :deployment do
gem 'capistrano', '~>2.15'
gem 'chef'
end
@jbgo
jbgo / tictactoe.rb
Created March 7, 2014 19:31
Interactive tic tac toe game
class TicTacToeApp
NIL_GAME = [
[nil, nil, nil],
[nil, nil, nil],
[nil, nil, nil]
]
def initialize
@game = NIL_GAME
@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 / 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