Skip to content

Instantly share code, notes, and snippets.

@leonsas
leonsas / grokking_the_gil.py
Created May 19, 2017 19:47
Grokking the GIL and atomic ops
# Tweaked from https://emptysqua.re/blog/grok-the-gil-fast-thread-safe-python/
import threading
for i in range(100):
n = 0
def foo():
global n
n += 1
threads = []
@leonsas
leonsas / custom_numpy_assertions.py
Created May 18, 2017 01:12
Custom Django/Python Assertions through Numpy
class NumpyAssertions:
def assertAlmostEqualNP(self, lval, rval, atol=None):
np.testing.assert_allclose(lval, rval, atol=atol)
class AlmostEqualityNumpyTest(TestCase, NumpyAssertions):
def test_numpy_almost_equal(self):
self.assertAlmostEqualNP(44.55, 44.75, atol=0.05)
@leonsas
leonsas / audit.py
Created August 9, 2016 18:35
Django AuditTrail
"""
From https://code.djangoproject.com/wiki/AuditTrail
Modified to allow `exclude_fields` options.
"""
from django.dispatch import dispatcher
from django.db import models
from django.core.exceptions import ImproperlyConfigured
from django.contrib import admin
import copy
@leonsas
leonsas / disable_signals.py
Created June 8, 2016 22:10 — forked from RobertKolner/disable_signals.py
Temporarily disable all signals in django.
from collections import defaultdict
from django.db.models.signals import *
class DisableSignals(object):
def __init__(self, disabled_signals=None):
self.stashed_signals = defaultdict(list)
self.disabled_signals = disabled_signals or [
pre_init, post_init,
pre_save, post_save,
import dateutil.parser
import optparse
from Queue import Queue
import tempodb
from threading import Thread
class Worker(Thread):
"""Thread executing tasks from a given tasks queue"""
def __init__(self, tasks):
Thread.__init__(self)
@leonsas
leonsas / index.html
Created July 22, 2012 21:19 — forked from mbostock/.block
Bubble chart
<!DOCTYPE html>
<meta charset="utf-8">
<style>
circle {
stroke: #fff;
}
</style>
<body>
@leonsas
leonsas / index.html
Created July 19, 2012 15:51
collision from dset
<html>
<head></head>
<body>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js?2.5.0"></script>
<script type="text/javascript">
var dataset = {"nodes": [{"statuses_count": 905, "name": "ThinkBlue Initiative", "friends_count": 1247, "followers_count": 120, "id": 171099799, "screen_name": "ThinkBlueInit"}, {"statuses_count": 218, "name": "Be Liquid", "friends_count": 261, "followers_count": 61, "id": 293498084, "screen_name": "MyWayToDelphi"}, {"statuses_count": 284, "name": "discover5oceans", "friends_count": 1952, "followers_count": 1075, "id": 105296106, "screen_name": "discover5oceans"}, {"statuses_count": 948, "name": "Katie Vogel", "friends_count": 1256, "followers_count": 327, "id": 18323274, "screen_name": "vogelian"}, {"statuses_count": 85, "name": "Nicole McLachlan", "friends_count": 96, "followers_count": 319, "id": 245773605, "screen_name": "pathtoprotect"}, {"statuses_count": 0, "name": "Valerio Pandolfi", "friends_count": 271, "followers_count": 43, "id": 561857821, "screen
@leonsas
leonsas / index.html
Created July 19, 2012 15:20
bubble chart
<html>
<head></head>
<body>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js?2.5.0"></script>
<script type="text/javascript">
var dataset = {"nodes": [{"statuses_count": 905, "name": "ThinkBlue Initiative", "friends_count": 1247, "followers_count": 120, "id": 171099799, "screen_name": "ThinkBlueInit"}, {"statuses_count": 218, "name": "Be Liquid", "friends_count": 261, "followers_count": 61, "id": 293498084, "screen_name": "MyWayToDelphi"}, {"statuses_count": 284, "name": "discover5oceans", "friends_count": 1952, "followers_count": 1075, "id": 105296106, "screen_name": "discover5oceans"}]};
var w = 500;
var h = 500;
var center = {x: w / 2, y: h / 2}
@leonsas
leonsas / index.html
Created July 19, 2012 15:16
bubble chart
<html>
<head></head>
<body>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js?2.5.0"></script>
<script type="text/javascript">
var dataset = {"nodes": [{"statuses_count": 905, "name": "ThinkBlue Initiative", "friends_count": 1247, "followers_count": 120, "id": 171099799, "screen_name": "ThinkBlueInit"}, {"statuses_count": 218, "name": "Be Liquid", "friends_count": 261, "followers_count": 61, "id": 293498084, "screen_name": "MyWayToDelphi"}, {"statuses_count": 284, "name": "discover5oceans", "friends_count": 1952, "followers_count": 1075, "id": 105296106, "screen_name": "discover5oceans"}]};
var w = 1000;
var h = 1000;
var center = {x: w / 2, y: h / 2}
import os
import arrow
from boto.s3.connection import S3Connection
S3_BACKUP_BUCKET = 'backup-bucket-name'
APP_NAME = 'myapp'
S3_REGION_HOSTNAME = 'e.g s3-us-west-1.amazonaws.com'
os.system('curl -o latest.dump `heroku pg:backups public-url --app %s`' % APP_NAME)