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
''' | |
Example code to show how it is possible to mock an entire module by patching | |
the sys.modules dict using mock ( http://www.voidspace.org.uk/python/mock/ ). | |
''' | |
from mock import patch, MagicMock | |
def test_import_patching(): | |
module_mock = MagicMock() | |
with patch.dict('sys.modules', **{ |
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 | |
set -e | |
git_dir=$(git rev-parse --git-dir) | |
rebase_dir=$git_dir/rebase-apply | |
if [ ! -d $rebase_dir ] | |
then | |
echo 'rebase/apply not in progress' >&2 | |
exit 1 | |
fi | |
patch_number=$(cat $rebase_dir/next) |
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
remove_trailing_whitespace_from_changed_lines() { | |
patch=$(mktemp --tmpdir remove-trailing-whitespace-patch-XXXXX) | |
git diff --cached --no-color --diff-filter=M > "$patch" | |
git apply --index --reverse "$patch" | |
git apply --index --whitespace=fix "$patch" | |
rm "$patch" | |
} |
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
### Keybase proof | |
I hereby claim: | |
* I am daragh on github. | |
* I am daragh (https://keybase.io/daragh) on keybase. | |
* I have a public key whose fingerprint is 0770 6EE5 1893 13FE DB61 11C2 71AF 3537 99D5 412A | |
To claim this, I am signing this object: |
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 | |
(code,) = sys.argv[1:] | |
func = eval(code) | |
lines = [line[:-1] if line[-1] == '\n' else iine for line in sys.stdin] | |
lines.sort(key=func) | |
for line in lines: | |
print(line) |
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 pretty_table(rows, sep=' | '): | |
rows = [[str(item) for item in row] for row in rows] | |
columns = zip(*rows) | |
widths = [max(len(item) for item in column) for column in columns] | |
padded = [ | |
[item.ljust(width) for (item, width) in zip(row, widths)] | |
for row in rows | |
] | |
return '\n'.join(sep.join(row) for row in padded) |
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 | |
from tempfile import mkstemp | |
from argparse import ArgumentParser | |
def main(argv): | |
parser = ArgumentParser() |
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 hashlib | |
from argparse import ArgumentParser | |
def main(args): | |
parser = ArgumentParser() |
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
<!DOCTYPE HTML> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
</head> | |
<body> | |
<div id="elm"></div> |
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 | |
import sys | |
import asyncio | |
import argparse | |
from redis import StrictRedis | |
class Async: |