Skip to content

Instantly share code, notes, and snippets.

Andrew Godwin andrewgodwin

Block or report user

Report or block andrewgodwin

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View benchmark.txt
Benchmark results:
Date: 2016/03/20
Version: asgi_redis 0.8.3 / daphne master / channels master / cpython 2.7.11
Environment: AWS, 3x m3.large (1 daphne, 1 worker, 1 redis)
Source: 1x m3.medium, different AZ, ab for HTTP, channels benchmarker for WS
HTTP GET, Django View (concurrency 10, 10,000 total)
Failures: 0.0%
Rate: 160 req/s
View speedplay.py
#!/usr/bin/python
import sys
import subprocess
import random
terms = [t.lower() for t in sys.argv[1:]]
if not terms:
print "No search terms supplied"
sys.exit(1)
View server.yaml
# Main Nginx router
www-router:
image: andrewgodwin/www-router
environment:
www.aeracode.org: aeracode-varnish
aeracode.org: redirect:www.aeracode.org
www.codingponies.com: codingponies
codingponies.com: redirect:www.codingponies.com
View whynot.sql
-- This presents an example of rendering templates in the database.
-- DO NOT DO THIS! It's a terrible idea, and just example for my talk
-- which you can see at https://speakerdeck.com/andrewgodwin/dubious-database-design
CREATE EXTENSION plpythonu;
-- Table to store template HTML by name
CREATE TABLE templates (
"name" text PRIMARY KEY,
"template" text
@andrewgodwin
andrewgodwin / profile-this.py
Created Aug 11, 2015
Handy profiler pattern
View profile-this.py
import cProfile, pstats, StringIO
pr = cProfile.Profile()
pr.enable()
# ... do something ...
pr.disable()
s = StringIO.StringIO()
sortby = 'cumulative'
ps = pstats.Stats(pr, stream=s).sort_stats(sortby)
View gist:7731b20eccfbe54a25d1

Small bag / wearing

  • Passport (+I-797B)
  • Hoodie
  • Bluetooth headphones
  • Surface
  • 3DS/Vita (+games for 3DS)
  • Nexus 9
  • Kindle
View gist:5fb29282a3f582f4e437
from collections import deque
def dependency_sort(initial, dependency_func):
"""
Generic dependency sorting algorithm; supply an initial list of IDs as
"initial", and a callable that takes an ID and returns a list of IDs as
"dependencies".
The resultant list is in order from leaf nodes (no dependencies) to stems.
"""
View 0001.py
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
]
View gist:064b7b5d1adf6e8533b3
class X:
@staticmethod
def y(self):
return 3
z = [y]
>>> X.y
<function X.y at 0x7fc5e5ca90d0>
View gist:a796c7c1ebcb1f98a48a
from __future__ import unicode_literals
from django.core import validators
from django.db import models, migrations
from django.utils import timezone
class Migration(migrations.Migration):
dependencies = [
You can’t perform that action at this time.