Skip to content

Instantly share code, notes, and snippets.

View zerowidth's full-sized avatar

Nathan Witmer zerowidth

View GitHub Profile
@zerowidth
zerowidth / git_prompt.sh
Created September 22, 2009 22:43
bash promptery for git + custom colored dirty flags
# assuming you have the +bash_completion variant of git installed (macports)
# and are including bash completion's setup:
if [ -f /opt/local/etc/bash_completion ]; then
. /opt/local/etc/bash_completion
fi
TEXT_BLACK='\[\e[0;30m\]' # Black - Regular
TEXT_RED='\[\e[0;31m\]' # Red
TEXT_GREEN='\[\e[0;32m\]' # Green
TEXT_YELLOW='\[\e[0;33m\]' # Yellow
@zerowidth
zerowidth / rack-streaming-proxy.rb
Created November 15, 2009 20:17
rack-streaming-proxy example code
require "servolux"
require "net/http"
require "uri"
# see: http://github.com/aniero/rack-streaming-proxy for the latest code
# or: sudo gem install rack-streaming-proxy --source http://gemcutter.org
module Rack
class StreamingProxy
@zerowidth
zerowidth / module ancestry.txt
Created November 17, 2009 23:09
ancestry in ruby
$ irb
>> module A; end
=> nil
>> module B; end
=> nil
>> module C; end
=> nil
>> module B; include A; end
=> B
>> class X; include B; end
class ParentDocument
include MongoMapper::Document
# parent document has ... well, whatever.
timestamps!
many :nodes do
# root documents only
def roots
@zerowidth
zerowidth / super_semantics.rb
Created March 4, 2010 16:26
ruby 1.8.7 p249 bug
class A
def foo
"foo!"
end
end
class B < A
def foo
lambda { super }
end
# as of 2010-04-01
export PATH=/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/local/mysql/bin:$PATH:/Users/nathan/scripts
export PATH=/Users/nathan/bin:/Users/nathan/bin/gitflow:/opt/local/lib/postgresql84/bin:$PATH
export LD_LIBRARY_PATH=/opt/local/lib
# export EDITOR="/Users/nathan/bin/mate_wait"
# export EDITOR="/Users/nathan/bin/mvim -f" # -f means don't fork, wait for changes
export EDITOR="/opt/local/bin/vim -f"
# export EDITOR="/opt/local/bin/mvim -f"
@zerowidth
zerowidth / ar_literals.rb
Created June 22, 2010 23:19
DEFAULT literals in AR for postgres defaults (via @copiousfreetime)
# Force ActiveRecord to insert the 'DEFAULT' literal for columns which
# are non-null but do not have a default that AR understands.
#
# MySQL is lenient in that if you insert a NULL in something with a default,
# the database will just insert the default anyway. Postgres is not so kind:
# it'll do exactly what you told it, causing an error.
# Usually AR can figure out the default for a column, but if it's a default
# value that the connection adapter can't figure out, it'll insert a NULL.
# So: allow explicit 'DEFAULT' literals (which is SQL standard) to be used instead
# where appropriate.
@zerowidth
zerowidth / git_funky.sh
Created July 16, 2010 17:57
git demo of what happens when you try to push to a working copy
#!/bin/sh
# try out cloning and pushing using a working copy in git
#
function log() {
echo
echo "***** $1"
echo
}
@zerowidth
zerowidth / pivotal-post-receive.rb
Created July 25, 2010 22:19
git post-receive hook for pivotal tracker
#!/usr/bin/env ruby
# git post-receive hook that posts the log messages to pivotal tracker
# for automatic updates of stories.
# See http://www.pivotaltracker.com/help/api?version=v3#scm_post_commit
# for more information
require "cgi"
begin
@zerowidth
zerowidth / client.rb
Created July 27, 2010 01:12
module methods and super
# A rough example of how I'm putting module method overrides to use.
# This allows me to add functionality to methods without having to
# do method aliasing, and it's easy to enable/disable things too.
module Search
def search(query, opts={})
request("search", :query => query).results
end
end