Skip to content

Instantly share code, notes, and snippets.

View dvcolgan's full-sized avatar
🦆

David Colgan dvcolgan

🦆
View GitHub Profile
@dvcolgan
dvcolgan / main.py
Last active March 2, 2023 15:17
For the Python Tenacity library, mock the retry decorator for faster tests that don't actually wait
from tenacity import retry, stop_after_attempt, wait_exponential
@retry(reraise=True, stop=stop_after_attempt(5), wait=wait_exponential(multiplier=1, min=4, max=10))
def do_something_flaky(succeed):
print('Doing something flaky')
if not succeed:
print('Failed!')
raise Exception('Failed!')
@dvcolgan
dvcolgan / _thing_create_form.html
Created April 6, 2018 16:10
Simple PJAX in Django without fancy libraries
<form novalidate action="{% url 'thing_create' %}" method="POST" id="thing-form">
{% csrf_token %}
{{ form }}
<input type="submit" value="Submit" />
</form>
@dvcolgan
dvcolgan / r
Last active April 25, 2016 18:29
A simple http command line client
#!/usr/bin/python2.7
import sys
import requests
import json
contents = json.loads(open('.httprc').read())
url_prefix = contents['url_prefix']
method = sys.argv[1].lower()
url = sys.argv[2]