Skip to content

Instantly share code, notes, and snippets.

@brianm
brianm / bash_prompt.sh
Last active May 16, 2023 15:04
Encode $0 into color of hostname in PS1
# assumes 256 color support, do your normal case thing, etc
local green="\[\033[38;5;156m\]"
local blue="\[\033[38;5;153m\]"
local red="\[\033[38;5;009m\]"
local reset="\[\033[00m\]"
local git_stuff='$(__git_ps1 "\[\033[31m\]<\[\033[01m\]%s\[\033[22m\]>\[\033[00m\]")'
local status_color="\$(if [ \$? = 0 ]; then echo \"${green}\"; else echo \"${red}\"; fi )"
PS1="${status_color}\h${reset}:${blue}\w${git_stuff}${reset}$ "
@piscisaureus
piscisaureus / pr.md
Created August 13, 2012 16:12
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@schmurfy
schmurfy / gist:3199254
Created July 29, 2012 14:33
Install pandoc Mac OS X 10.8
# Install MacTex: http://mirror.ctan.org/systems/mac/mactex/mactex-basic.pkg
$ sudo chown -R `whoami` /usr/local/texlive
$ tlmgr update --self
$ tlmgr install ucs
$ tlmgr install etoolbox
# Install pandoc view homebrew
@rosskarchner
rosskarchner / gist:1831953
Created February 15, 2012 00:14
CooksIllustrated.com recipe database to Evernote
import mechanize, codecs
from BeautifulSoup import BeautifulSoup, Comment
ci_login_url="https://auth.cooksillustrated.com/"
recipe_search_root="http://www.cooksillustrated.com/search/results.asp"
initial_query='?query=+&filters=&sort=&filters=type:Recipe'
br = mechanize.Browser()
br.open(ci_login_url)
from fabric.api import *
import time
env.name = 'myapp'
env.python = 'python2.6'
env.time = int(time.time())
env.buildroot = '/tmp/%s/%d' % (env.name, env.time)
env.app = '%s/%s' % (env.buildroot, env.name)
env.deploy = '/usr/local/%s/releases' % env.name
@mattheworiordan
mattheworiordan / rate_limit.js
Created July 15, 2011 14:49
Rate limiting function calls with JavaScript and Underscore.js
/* Extend the Underscore object with the following methods */
// Rate limit ensures a function is never called more than every [rate]ms
// Unlike underscore's _.throttle function, function calls are queued so that
// requests are never lost and simply deferred until some other time
//
// Parameters
// * func - function to rate limit
// * rate - minimum time to wait between function calls
// * async - if async is true, we won't wait (rate) for the function to complete before queueing the next request