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
# 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 = [] |
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
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) | |
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
""" | |
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 |
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
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, |
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
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) |
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
from PIL import Image | |
import glob | |
filenames = glob.glob('*.png') | |
for f in filenames: | |
img = Image.open(open(f)) | |
(w,h) = img.size | |
cropped_image = img.crop((0,0,w,w)) | |
cropped_image.save(open('cropped_'+f,'w'), 'PNG') |
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
Verifying that +leonsas is my openname (Bitcoin username). https://onename.com/leonsas |
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
var linkranks = {"Paris": {"Rh%C3%B4ne-Alpes": 0.003025313292630801, "Women%27s_march_on_Versailles": 0.001960156560233164, "Tuileries_Palace": 0.001960156560233164, "Jacques_Chirac": 0.005880469680699492, "Metropolitan_area": 0.0002820987671835713, "Liverpool": 0.0006656336150812513, "Church_of_Saint-Sulpice,_Paris": 0.001960156560233164, "Luxembourg_in_the_Eurovision_Song_Contest": 0.0007010761311666402, "Basilica_of_St_Denis": 0.003920313120466328, "Eure": 0.0033556310996435625, "China": 0.0003702107970702168, "A86_autoroute": 0.003920313120466328, "Caen": 0.0033556310996435625, "Euro": 0.002460631271808035, "Azerbaijan_in_the_Eurovision_Song_Contest": 0.0007010761311666402, "Democratic_Republic_of_the_Congo": 0.0011675251349560507, "Paris_Match": 0.001960156560233164, "Mus%C3%A9e_d%27Art_Moderne_de_la_Ville_de_Paris": 0.001960156560233164, "List_of_films_set_in_Paris": 0.001960156560233164, "President_of_France": 0.003920313120466328, "Place_Dauphine": 0.001960156560233164, "Eurovision_Song_Contest_1967": |
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
function forEachHTMLCollection(collection, fn){ | |
for (var i = collection.length - 1; i >= 0; i--) { | |
fn(collection[i]); | |
}; | |
} | |
ps = document.getElementsByTagName('p'); | |
forEachHTMLCollection(ps, function(e){ | |
e.style.color = 'white'; |
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
CITIES = [ | |
('Chicago', 'chicago'), | |
('New_York_City', 'newyork'), | |
('Los_Angeles', 'losangeles'), | |
('Paris', 'paris'), | |
('Tokyo', 'tokyo'), | |
] | |
command_str =""" | |
/Users/leonsas/projects/temp/capturejs/capture.js --uri http://en.wikipedia.org/wiki/%s \ |
NewerOlder