Skip to content

Instantly share code, notes, and snippets.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
function cd {
if [ -f "$1" ]; then
# Sometimes I drag-n-drop files onto the terminal because it's easy
# so I can 'cd <filename>' and have it cd to the parent directory of that file
builtin cd "`dirname \"$1\"`"
elif [ $# == 0 ]; then
# If a virtualenv is activated then a no-parameter 'cd' will take you
# to the virtualenv root.
if [ -n $VIRTUAL_ENV ]; then
builtin cd $VIRTUAL_ENV
@DamnedFacts
DamnedFacts / gist:2ef7e5a9ff5a359fc89f
Created May 19, 2014 21:46
Trick to execute Bash scripts line-by-line
#!/usr/bin/env bash
set -x
trap read debug
< YOUR CODE HERE >
@DamnedFacts
DamnedFacts / gist:67e6ccbdd70fc59ea6ba
Created May 16, 2014 23:20
A natural sort using Collections
import re,collections
def sort_naturally(l):
""" Sort the given list in the way that humans expect.
"""
convert = lambda text: int(text) if text.isdigit() else text
alphanum_key = lambda key: [convert(c) for c in re.split('([0-9]+)', key[0])]
l.sort( key=alphanum_key )
return l
collections.OrderedDict(sort_naturally(a_dict.items()))
@DamnedFacts
DamnedFacts / gist:9f58fb8bba2d2b9b1928
Last active August 29, 2015 14:01
A one-liner for searching Maildirs for a particular strings over a particular date range.
# Change {0,0} to pick the relative date range to search, i.e. {3,5} searches 3-5 days ago.
# Change <hostname> to be the base name used in naming your Maildir files
for i in {0..0}; do find . -name \*<hostname>\* -mtime $i -exec grep -m1 -Hi "^Subject:" {} \; ; done