This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
''' | |
The only dependencies for this script are SQLAlchemy 0.9.2, psycopg2 | |
2.5.2, and Postgres 9.3.2, so you should be able to use it for debugging | |
yourselves. Also, those are the exact same versions that are being used | |
in all our other environments, so this problem isn't caused by a slight | |
version mismatch anywhere. | |
This test script connects to the Postgres DB, creates a table with a | |
text column, and then tries to write a Python dictionary object to the |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* | |
Copyright (c) 2013, Richard Emile Sarkis <rich@sarkis.info> | |
All rights reserved. | |
Redistribution and use in source and binary forms, with or without | |
modification, are permitted provided that the following conditions are met: | |
1. Redistributions of source code must retain the above copyright notice, this | |
list of conditions and the following disclaimer. | |
2. Redistributions in binary form must reproduce the above copyright notice, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3.4 | |
# A response to http://nbviewer.ipython.org/url/norvig.com/ipython/Fred%20Buns.ipynb | |
# Read more about it at https://blog.glyphobet.net/essay/2770 | |
import itertools | |
from collections import Counter | |
lock_size = 10 | |
WORDS = set(w.lower() for w in open('words4.txt').read().split()) | |
norvig_improved_wordlock = ['spcmthdlfb', 'leyhwruoai', 'enmlrtacso', 'dsnpaylkte'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> db.dropDatabase(); | |
{ "dropped" : "test", "ok" : 1 } | |
> | |
> // These points are one degree apart, which (according to Google Maps) is about 110 km apart | |
> // at this point on the Earth. | |
> db.points.insert({location: [-122, 37]}); | |
> db.points.insert({location: [-122, 38]}); | |
> db.points.ensureIndex({location:"2d"}); | |
> | |
> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
import os | |
import os.path | |
for a in sys.argv[1:]: | |
for root, dirs, files in os.walk(a): | |
for f in files: | |
if f.startswith(':2e_') or f.startswith('._') or f.endswith('~') or f == '.DS_Store': | |
print "rm %r" % os.path.join(root, f) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){ | |
var promptURL=function (url){ | |
window.prompt("Copy short URL to clipboard:",url); | |
}; | |
var links=document.getElementsByTagName('link'); | |
for(var i=0;i<links.length;i++){ | |
var tag=links[i]; | |
if(tag.getAttribute('rel')=='shorturl' || tag.getAttribute('rel')=='shortlink' || tag.getAttribute('id')=='shorturl' || tag.getAttribute('id')=='shortlink'){ | |
promptURL(tag.getAttribute('href')); | |
return; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo(object): | |
def foo(arg): | |
pass | |
# comment |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
OlderNewer