Skip to content

Instantly share code, notes, and snippets.

/* Funky JavaScript patterns from Resig's talk @ VanJS in Vancouver today. */
/* url: http://ejohn.org/apps/learn/bind.html */
/* loop => callback construct utilizing .call() for each member of the input array */
function loop(array, fn){
for ( var i = 0; i < array.length; i++ ) {
fn.call(array, array[i], i);
}
<?php
interface dRF_Cache_Interface {
public function get($id);
public function getList($ids);
public function set($id, $value);
desc "get Master"
task :get_master_info, :roles => :new do
run 'echo "SHOW MASTER STATUS" | mysql -u root --password=root_pass' do |ch, stream, data|
set :master_info, data.split("\n").pop().split("\t")
end
set_master
end
@jeffgca
jeffgca / unless.js
Created December 26, 2010 21:03
A goofy, async, incomplete implementation of unless
/**
* user-space unless, some syntactic sugar from ruby implemented in JS
* @var {bool} statement - any statement in JS that evaulates to a boolean. Watch for truthiness here.
* @var {function} callback - adds the shiny sheen of async programming to this.
*/
window.unless = function(statement, callback) {
var returnValue = false;
args = [].slice.call(arguments);
if (args.length > 2) {
@jeffgca
jeffgca / gpull.sh
Created December 31, 2010 22:48
Nice git push and pull aliases
# from here: http://stackoverflow.com/questions/948354/git-push-current-branch/948364#948364
get_git_branch() {
echo `git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'`
}
alias gpull='git pull origin `get_git_branch`'
alias gpush='git push origin `get_git_branch`'
@jeffgca
jeffgca / Mongo_Shell_crib_sheet.js
Created January 3, 2011 21:18
Some common commands I still haven't committed to muscle memory
// Note: more here: http://www.mongodb.org/display/DOCS/dbshell+Reference
// also, scripting note: db = db.getSisterDB( "users" ) is a script equiv of use users in the shell
// get rs status
rs.status()
// re-configure replicaset
config = rs.conf()
//manipulate the config data here
rs.reconfigure(config);
@jeffgca
jeffgca / isvm.sh
Created January 14, 2011 19:36
Stupid bash script to detec if we're running on a vm, and set a watchfile.
#!/bin/bash
IS_VM="No"
WATCHFILE="$HOME/.isVm"
if [ -f $WATCHFILE ]; then
exit;
fi
DMI_OUTPUT=`sudo dmidecode | awk '/Manufacturer: (Bochs|VMware)/ {print $2}'`
@jeffgca
jeffgca / rvm_rails3_install.sh
Created January 25, 2011 22:20
Getting RVM, Ruby 1.92 and Rails3 installed on my machine
# Resources:
# 1. http://amerine.net/2010/02/24/rvm-rails3-ruby-1-9-2-setup.html
# 2. http://rvm.beginrescueend.com/
# Dependencies: MacPorts, with readline and mysql5 installed
# Side note, under no circumstances should you run any of this using sudo.
# install rvm
bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )
@jeffgca
jeffgca / php52_macports_incantation.sh
Created January 26, 2011 23:15
In case you need to build php 5.2 with all the trimmings with Macports on Snow Leopard.
sudo port install php52 +apache2 +mysql5 +pear
@jeffgca
jeffgca / oplog_date.js
Created February 25, 2011 21:10
From boxed ice, how to get the last oplog date.
/* Choosing the right MongoDB oplog size can be difficult, especially if your usage is growing. So here’s quick way to see what the last item in the oplog is. If your down slave or backup is older that this, it won’t be able to resync: */
use local
new Date(db.oplog.rs.find().sort({$natural:1}).limit(1).next()["ts"]["t"])