Skip to content

Instantly share code, notes, and snippets.

@willhardy
willhardy / pip-compile-keepcomments.py
Created November 19, 2017 11:46
Script to keep comments in requirements files after running pip-compile
#!/usr/bin/env python
import subprocess
import sys
import os.path
"""Script that runs pip-compile, but keeps comments.
Provide the same arguments as you would pip-compile, ensure that the filename is last.
The logic here is very simple and we don't care about edge cases, so it may break easily.
@willhardy
willhardy / encode_selection.js
Created August 9, 2012 15:28
Encoding selection of integers in a short, URL-friendly string
/*
A few functions for encoding a selection as a short, USL-friendly string.
This can be used with history.js to update the URL based on the current selection and eventually decode it and display the relevant selection.
NB MS won't like "const"
*/
@willhardy
willhardy / gist:2279849
Created April 2, 2012 01:05
Python modulo
from decimal import Decimal
print(-5 % 360) # 355
print(-5.0 % 360) # 355.0
print(Decimal(-5) % 360) # -5
@willhardy
willhardy / epio-client_cp-exclude.diff
Created August 9, 2011 23:19
epio-client: upload cp with .epioexclude
diff -r 8ce6f774762a epio/commands/upload.py
--- a/epio/commands/upload.py Tue Aug 09 20:57:55 2011 +0100
+++ b/epio/commands/upload.py Wed Aug 10 00:46:04 2011 +0200
@@ -18,19 +18,13 @@
repo_dir = tempfile.mkdtemp(prefix="epio-upload-")
try:
# Copy the files across
+ additional_excludes = ['.git', '.gitignore', '.svn', '.epio-git', '.hg']
+ base_command = ["rsync", "-a", "--exclude-from=.epioignore", ".", repo_dir]
subprocess.Popen(
@willhardy
willhardy / easy_race.py
Created August 4, 2011 18:27
Context manager for regression testing makedirs race condition
import os
import errno
import time
import shutil
from threading import Timer
from contextlib import contextmanager
@contextmanager
def makedirs_with_easy_race(pth, wait=0.5):
""" Context manager for testing code that might suffer from a
@willhardy
willhardy / output
Created July 23, 2011 12:28
Cadel versus Schleck
After 167 of 167 riders:
Andy Schleck's predicted time is 60:05 (based on 2010 TDF ride for yellow, mean - 0.5 std.dev)
Cadel's predicted time is 58:22 (based on 2008 TDF ride for yellow, mean - 1.3 std.dev)
Cadel would be faster by 1:43
@willhardy
willhardy / gist:1017488
Created June 9, 2011 19:19
decimal module strangeness
import decimal
a = decimal.Decimal(0)
isinstance(a, decimal.Decimal) # True
reload(decimal)
isinstance(a, decimal.Decimal) # False
decimal.Decimal(a) # Exception!?
#!/usr/bin/env python
"""
Run Django Tests with full test coverage
This starts coverage early enough to get all of the model loading &
other startup code. It also allows you to change the output location
from $PROJECT_ROOT/coverage by setting the $TEST_COVERAGE_OUTPUT_DIR
environmental variable.