Skip to content

Instantly share code, notes, and snippets.

@glyphobet
glyphobet / engineering_guidelines.md
Last active December 11, 2015 15:38
Technical Maxims
@glyphobet
glyphobet / gist:4175875
Created November 30, 2012 14:00
Arrrgh git
$ git pull
remote: Counting objects: 36, done.
remote: Compressing objects: 100% (15/15), done.
remote: Total 27 (delta 19), reused 20 (delta 12)
Unpacking objects: 100% (27/27), done.
Von github.com:glyphobet/myproject
581f38f..a83e75b mybranch -> origin/mybranch
There is no tracking information for the current branch.
Please specify which branch you want to merge with.
See git-pull(1) for details
@glyphobet
glyphobet / click_dispatch.js
Created November 9, 2012 14:29
Dispatch click events on <a>nchor tags to Backbone.js's Router
// This is the proper way to catch click events on <a>nchor tags and dispatch them to Backbone.js's Router instead
$('a').live('click', function (event) {
var href = $(event.target).attr('href');
if (href && // href attribute is defined
! /^\w+\:/i.exec(href) && // href does not begin with 'protocol:'
event.which == 1 && // first mouse button was pressed
! event.metaKey ) { // Command (Mac OS) or Ctrl (Windows) was not held down (otherwise the user wanted a new window from this link)
app.router.navigate(href, {trigger:true});
return false;
}
@glyphobet
glyphobet / SF-CA-2012.csv
Created October 16, 2012 21:01
San Francisco California 2012 Endorsements
San Francisco California 2012 Endorsements
Democratic Green
Proposition 30 Y Y
Proposition 31 N N
Proposition 32 N N
Proposition 33 N N
Proposition 34 Y Y
Proposition 35 Y N
Proposition 36 Y Y
Proposition 37 Y Y
@glyphobet
glyphobet / .bashrc-ack.sh
Created September 26, 2012 22:34
find ack
# Find ack on the system (even if it's been installed as ack-grep (linux) or ack-5.12 (MacPorts) and set up aliases
if [ "`compgen -c ack`" ]; then
ACK=`compgen -c ack | head -n 1`
alias ack=${ACK}
alias ackp="${ACK} --pager=less\ -R"
fi
# Note: this is not idempotent
@glyphobet
glyphobet / jquery.putdel.js
Created September 16, 2012 17:39
jQuery.put() and jQuery.del() functions for HTTP PUT and DELETE methods
/* Extend jQuery with functions for PUT and DELETE requests. */
/* Based on http://homework.nwsnet.de/news/9132_put-and-delete-with-jquery */
(function(){
function _ajax_request(url, data, callback, type, method) {
if (jQuery.isFunction(data)) {
callback = data;
data = {};
}
return jQuery.ajax({
@glyphobet
glyphobet / ChromeMacOSXFixes.sh
Created September 8, 2012 15:48
Fixes for Chrome and Mac OS X
# Use Mac OS X's print dialog instead of Chrome's idiotic print dialog
defaults write com.google.Chrome NSUserKeyEquivalents -dict-add 'Print Using System Dialog...' '@p' 'Print...' '~@p'
# Prevent Chrome from automatically deciding you want search results in German instead of English
find ~/Library/Application\ Support/Google/Chrome -name Preferences -print0 | xargs -0 perl -pi.bak -e 's{_google_url": "http://www.google.de/",}{_google_url": "http://www.google.com/",}g;'
# Add Quit menu item to Finder
defaults write com.apple.finder QuitMenuItem -bool yes
# Change Preview to default to "Single Page" view
@glyphobet
glyphobet / pre-commit.sh
Created July 17, 2012 10:53
self-installing git-hook to prevent accidentally committing pdb.set_trace() calls
#!/bin/bash
mybasename=`basename $0`
if [ ! -e .git/hooks/${mybasename} ] ; then
ln -s ../../git-hooks/${mybasename} .git/hooks/${mybasename}
fi
set_traces=`git diff --cached -Gpdb\.set_trace\(\) | grep '^\+'`
if [ ! -z "$set_traces" ] ; then
@glyphobet
glyphobet / elapsed_time.py
Created June 3, 2012 10:46 — forked from mwhooker/elapsed_time.py
humanize elapsed time
def elapsed_time(start, end):
"""
>>> from datetime import datetime
>>> elapsed_time(datetime(2000, 1, 1), datetime(2000, 1, 1, 20, 15))
'20 hours, and 15 minutes'
>>> elapsed_time(datetime(2000, 1, 1), datetime(2000, 1, 1, 0, 1))
'1 minute'
>>> elapsed_time(datetime(2000, 1, 1), datetime(2000, 1, 2, 0, 1))
'1 day, and 1 minute'
>>> elapsed_time(datetime(2000, 1, 1), datetime(2000, 1, 2, 2, 3, 4))
@glyphobet
glyphobet / immutabledict.py
Created May 13, 2012 10:52
Immutable dictionary in Python
class ImmutableDict(dict):
def __setitem__(self, key, value):
raise TypeError("%r object does not support item assignment" % type(self).__name__)
def __delitem__(self, key):
raise TypeError("%r object does not support item deletion" % type(self).__name__)
def __getattribute__(self, attribute):
if attribute in ('clear', 'update', 'pop', 'popitem', 'setdefault'):
raise AttributeError("%r object has no attribute %r" % (type(self).__name__, attribute))