This file contains hidden or 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
import os | |
import shutil | |
import tempfile | |
from contextlib import contextmanager | |
@contextmanager | |
def tmpdir(suffix='', prefix='tmp', dir=None): | |
dirname = tempfile.mkdtemp(suffix=suffix, prefix=prefix, dir=dir) | |
yield dirname | |
shutil.rmtree(dirname) |
This file contains hidden or 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
import os | |
from contextlib import contextmanager | |
@contextmanager | |
def chdir(dirname): | |
old = os.getcwd() | |
os.chdir(dirname) | |
yield old | |
os.chdir(old) |
This file contains hidden or 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
Today's lesson: Never call your module types.py if you plan to run | |
Python from when standing in the same directory. It took me some | |
time to figure out what was going on: | |
$ touch types.py # empty file | |
$ python | |
Traceback (most recent call last): | |
File "/usr/lib/python2.7/site.py", line 68, in <module> | |
import os | |
File "/usr/lib/python2.7/os.py", line 398, in <module> |
This file contains hidden or 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/sh | |
# | |
# Open nautilus in current directory by default | |
# | |
if [ -z $* ]; then | |
nautilus . | |
else | |
nautilus $* |
This file contains hidden or 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 node | |
/* | |
* CLI frontend for jshint.js | |
* | |
* When I wrote this, I didn't know there is | |
* | |
* a much more mature project at: | |
* https://github.com/jshint/node-jshint | |
* |
This file contains hidden or 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/sh | |
# Remove dotencode from a Mercurial repository. | |
if [ -z $1 ]; then | |
echo "usage: dotdecode REPOSITORY" | |
echo | |
echo "A backup will be made to REPOSITORY.dotencode" | |
exit 1 | |
fi |
This file contains hidden or 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
# Turn prompt off | |
function poff { | |
PS1='$ ' | |
} | |
# Turn prompt on | |
function pon { | |
# Todo: make this work on mac | |
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' | |
} |
This file contains hidden or 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/python | |
""" | |
howoldami - Compute your age in days and years. | |
Unix has whoami, but it's missing howoldami. No longer! | |
$ howoldami | |
You are 15884 days old (or 43.49 years) |
This file contains hidden or 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
""" | |
This goes in the PYTHONSTARTUP file. | |
Example: | |
>>> pubdir([]) | |
['append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort'] | |
""" | |
__pubdir_no_arg = [] |