Skip to content

Instantly share code, notes, and snippets.

View christoomey's full-sized avatar

Chris Toomey christoomey

View GitHub Profile
@christoomey
christoomey / gist:759231
Created December 29, 2010 23:44
Git aware command T functions. Use git repo top level as Command T context, else top level
function! Command_T_Local() "Go to the root of the git repo, then CommandT
"Ask git for the root of the git repo (as a relative '../../' path)
let git_top = system('git rev-parse --show-cdup')
let git_fail = 'fatal: Not a git repository'
if strpart(git_top, 0, strlen(git_fail)) == git_fail
" Above line says we are not in git repo. Ugly. Better version?
call Command_T_Work()
else
" Move working dir to root of repo, then CommandT
execute ":cd ./" . git_top
@christoomey
christoomey / gist:760246
Created December 30, 2010 20:21
Have git output the contents of a deleted file from the commit before it was deleted
function git_show_deleted_file {
# Rev-list command gets commit that deleted the file, ^ gets prior commit
git show $(git rev-list -n 1 HEAD -- $1)^:$1
}
@christoomey
christoomey / gist:801888
Created January 29, 2011 14:51
Python tab completion using readline
#!/usr/bin/python
import readline
readline.parse_and_bind("tab: complete")
class VolcabCompleter:
def __init__(self,volcab):
self.volcab = volcab
def complete(self,text,state):
@christoomey
christoomey / gist:805138
Created February 1, 2011 00:17
Some useful steps in setting up my webfaction image
# Install git http://docs.webfaction.com/software/git.html#git-install-home
# Install vim <current-version> using techniques above, ie wget, configure, make, make install
echo 'alias python=python2.6' > ~/.bash_profile # Set default python => 2.6
easy_install-2.5 -s ~/bin -d ~/lib/python2.5 python-dateutil # Get dateutil, also, general python module
http://docs.webfaction.com/software/git.html#git-install-home
import sys.path
@christoomey
christoomey / stringInterpolation.js
Created April 16, 2011 20:56
Extend String prototype to include a subs method to interpolate a string
// From Douglas Crockford's http://javascript.crockford.com/remedial.html
//
// Usage:
// var person = { name: "James", age: 22 };
// var template = "Hello {name}, how does it feel to be {age}?";
// var personalGreeting = template.subs(person);
// => "Hello James, how does it feel to be 22?"
if (!String.prototype.subs) {
String.prototype.subs = function (o) {
@christoomey
christoomey / ssh-key-copy-cmd.sh
Created April 17, 2011 17:58
Copy a public key to a remote host
# Copy the id_rsa.pub public key from local box to remote server
user@hostname "echo `cat ~/.ssh/id_rsa.pub` >> ~/.ssh/authorized_keys"
@christoomey
christoomey / log.js
Created April 29, 2011 00:29
Wrapper for console.log
// usage: log('inside coolFunc',this,arguments);
// http://paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
window.log = function(){
log.history = log.history || []; // store logs to an array for reference
log.history.push(arguments);
if(this.console){
console.log( Array.prototype.slice.call(arguments) );
}
};
@christoomey
christoomey / gist:956173
Created May 4, 2011 22:25
Bash function to list all symlinks in current directory
# List all symlinks in current directory
lns() {
find ./ -type l -maxdepth 1 | awk '{ sub(/.\/+/, ""); print }'
}
# List broken symlinks under current directory
lnsm() {
find -L ./ -type l -maxdepth 1
}
#!/usr/bin/env ruby
#
# A quick script to dump an overview of all the open issues in all my github projects
#
require 'octokit'
require 'awesome_print'
require 'rainbow'
@christoomey
christoomey / gist:965669
Created May 11, 2011 00:23
Javascript object literal code organization pattern
// Object literal code organization pattern. From Rebecca Murphy's blog:
// http://blog.rebeccamurphey.com/2009/10/15/using-objects-to-organize-your-code
var myModule = {
'config' : {
'option1' = val,
'cached_elem' = $(this)
},
'init' : function(config) {
// provide for custom configuration via init()