Skip to content

Instantly share code, notes, and snippets.

@dhepper
dhepper / patch_import.py
Created November 24, 2018 16:09
A module that patches __import__ to print some information about imported modules.
import builtins
builtin_import = builtins.__import__
paths = set()
def __import__(*args, **kwargs):
module = builtin_import(*args, **kwargs)
@dhepper
dhepper / install.sh
Last active September 5, 2018 09:11
One-line command to install requirements for an AWS lambda function
docker run -it --mount type=bind,source="$(pwd)",target=/build dacut/amazon-linux-python-3.6 bash -c "cd /build && pip3 install -r requirements.txt -t ./"
@dhepper
dhepper / coffee_machine_machine.py
Created December 2, 2017 16:34
Script to generate code for Coffee Machine Machine code golf
# Script to generate code for Coffee Machine Machine code golf
# https://codegolf.stackexchange.com/questions/149585/coffee-machine-machine
cm = """________._________
| | \ - /
| || | \ - /
| || |___\___/
| || | X
| | ___
| | / - \\
from urllib.parse import urlparse
from django.conf import settings
from django.http.request import validate_host
from channels.exceptions import DenyConnection
class BaseOriginValidator(object):
@dhepper
dhepper / statsd_instrument.py
Created November 8, 2012 17:02 — forked from chooper/statsd_instrument.py
Decorator to quickly add statsd (graphite) instrumentation to Celery task functions.
"""Decorator to quickly add statsd (graphite) instrumentation to Celery
task functions.
With some slight modification, this could be used to instrument just
about any (non-celery) function and be made abstract enough to customize
metric names, etc.
Stats reported include number of times the task was accepted by a worker
(`started`), the number of successes, and the number of times the task
raised an exception. In addition, it also reports how long the task took
@dhepper
dhepper / Guardfile
Created February 29, 2012 10:34 — forked from skade/Guardfile
Poor man's CI, Ruby edition
# gem install guard guard-shell; guard
guard 'shell' do
watch(%r{(.+)\.py}) do |m|
`django-admin.py test main`
end
end
@dhepper
dhepper / ci.sh
Created February 27, 2012 10:10
Poor man's CI
#!/bin/sh
touch -t 197001010101 .last_run
while `true`
do
if [ ! -z "`find . -name \"*.py\" -cnewer .last_run 2>/dev/null`" ] ; then
django-admin.py test main
touch .last_run
fi
sleep 1
vows = require('vows');
assert = require('assert');
vows.describe("Vows with asynchonous teardowns").addBatch({
"Context with long-running teardown": {
"is run first": function () {},
teardown: function () {
var callback = this.callback;
setTimeout(function () {
assert = require 'assert'
vows = require 'vows'
tornDown = false
vows.describe('Vows with asynchronous teardowns').addBatch
'Context with long-running teardown':
'is run first': () ->
teardown: () ->
setTimeout(() =>
tornDown = true
@dhepper
dhepper / vow_with_async_teardown_in_coffee.coffee
Created January 13, 2012 15:21
A Vow with asynchronous teardown in CoffeScript
assert = require 'assert'
vows = require 'vows'
tornDown = false
vows.describe('Vows with asynchronous teardowns').addBatch
'Context with long-running teardown':
'is run first': () ->
teardown: () ->
callback = @callback
setTimeout(() ->