Skip to content

Instantly share code, notes, and snippets.

View benspaulding's full-sized avatar

Ben Spaulding benspaulding

View GitHub Profile
import time
import sound
from scene import *
class TeaTimer(Scene):
def setup(self):
self.initial_time = int(60 * 1.5)
self.remaining_time = self.initial_time
self.center_x = self.size.w * 0.5
@captainsafia
captainsafia / usage.md
Last active April 19, 2017 20:03
A poor woman's filesystem watcher

To use watchman, run watchman file-to-watch sleep-time command-to-execute like so.

watchman test.txt 1 echo 'Tada!'
@codysoyland
codysoyland / prime_sieve.py
Last active April 23, 2017 14:24
A prime number generator using Python generators, inspired by concurrent prime sieve at http://play.golang.org/p/9U22NfrXeq
from itertools import count
def filter(input, prime):
for i in input:
if i % prime:
yield i
def get_primes(num):
g = count(2)
for _ in xrange(num):
@benspaulding
benspaulding / example.py
Last active April 28, 2017 16:10
Python class vs instance attributes
>>> class Foo(object):
... # Immutable objects are fine as class attrs.
... mystr = 'a'
... myint = 1
... mytpl = (1,)
...
... # But mutable objects often surprise you.
... mylst = []
... mydct = {}
>>> foo = Foo()
web: gunicorn -w4 -b0.0.0.0:$PORT app:app
@yakky
yakky / pico.py
Last active March 16, 2018 09:36
Micro hello world Python Web Framework Royal Rumble @PyCon 7
import django
DEBUG, ROOT_URLCONF, DATABASES, SECRET_KEY = 1, 'pico', {'default': {}}, 'p'
urlpatterns = [django.conf.urls.url(r'^(?P<name>\w+)?$', lambda request,
name: django.http.HttpResponse('hello %s!' % (name or 'world')))]
@jshell
jshell / BBFlakes.py
Created August 19, 2011 19:20
PyFlakes Script for BBEdit 10
#!/usr/bin/env python2.6
"""
A quick script to install into your `Application Support/BBEdit/Scripts` folder.
This runs PyFlakes (requires PyFlakes to be installed at `/usr/local/bin` -
try ``/usr/bin/easy_install-2.6 pyflakes==0.4.0``) and reformats the results
so that they show up in BBEdit's search results / error / warnings window. Then
the errors can be stepped through one at a time.
I've bound this to control-shift-V. You must save your Python file first before
running the check.
@heyimalex
heyimalex / rust-js.md
Created March 13, 2019 07:09
Looking at npm projects that are good candidates for being re-written in rust / webassembly!
@Valian
Valian / profile_middleware.py
Created May 6, 2017 14:13
Detailed Hotshot profiler middleware for Django
# Orignal version taken from http://www.djangosnippets.org/snippets/186/
# Original author: udfalkso
# Modified by: Shwagroo Team and Gun.io
# Further modified by: Jakub Skalecki (https://rock-it.pl)
import hotshot
import hotshot.stats
import textwrap
import os
@mixxorz
mixxorz / services.py
Last active January 21, 2020 16:52
Django Service Objects
from django import forms
from django.core.exceptions import ValidationError
from django.db import transaction
class InvalidInputsError(Exception):
def __init__(self, errors, non_field_errors):
self.errors = errors
self.non_field_errors = non_field_errors