Skip to content

Instantly share code, notes, and snippets.

View erikrose's full-sized avatar

Erik Rose erikrose

View GitHub Profile
#!/usr/bin/env python
"""BBEdit UNIX filter that wraps one or more optionally-indented,
hash-commented lines to 79 chars, preserving indentation.
Just select all the lines (in their entirety) the comment spans, and invoke.
Works with #, --, and //-style comments.
For example, this... ::
# Upping this to 10000 makes it 3x faster. 10000 takes 15.936s. 5000 takes 16.303s.
#!/usr/bin/env python
# How the corpus was built:
# 1. Start with the Belfry WebComics Index: http://new.belfrycomics.net/view/all. (Choose "All Comics" and "Daily" as filters.) Spider down all those linked pages.
# 2. Throw out the few (about 5) pages that are clearly not single comics. Doing this early makes it likely our training and test sets will still be close to 70/30.
# 3. Use this to divide into a training set (for optimizing weights and getting best-case performance) and a testing set (for seeing how we did on unseen data). We use a 70/30 split only because it is a common rule of thumb. Since I'm writing features by hand, I start with a small subset of the training set (30 comics) and validate on another small subset. If the validation goes poorly, we induct that validation set into the training set, look for patterns of error in it, and adjust the features to eliminate them. Then we validate against a new subset, and so on. Hopefully, we start to do okay before we run out of data. The test set is f
Type uWSGI, press enter: good stuff about uWSGI's blocking and restarting behavior
The GILectomy: entertaining low-level twiddling and benchmarks
Snek in the Browser: a novel approach to Python in the browser, with only a few hundred K overhead
Constructive Code Review, if you like to watch me prance around. Polished up a lot since the Mozilla onboarding version.
"When the abyss gazes back" should be great; I have yet to watch it
Modern Python Dictionaries is full of clever ideas
Static Types for Python goes over a little of how type inference works
The Fastest Fizzbuzz is a walkthrough of writing a JITing compiler based on PyPy infra
The Dictionary Even Mightier: more dict internals. Brandon Rhodes is always entertaining.

In preparation for the release of version 0.4.0 of the python client, we are transitioning to a new version of the letsencrypt-auto script. As most of you know, letsencrypt-auto is available as an alternative for OS packaging, on those operating systems that do not yet have backported packages. The new version of the script includes a number of important improvements:

  • A reproducible set of python package dependencies, enforced by version pinning and hash verification. (Previously, we trusted an HTTPS connection to PyPI for authenticity.)
  • The script now updates itself as well as the underlying python client. If you don't want this behavior, you can turn it off with --no-self-upgrade.
  • A git clone operation is no longer required; you can now download the script as a single file and run it.
  • Much faster execution, especially on the second and subsequent times it is run, and especially on slo
@erikrose
erikrose / lights.py
Last active December 26, 2015 00:29
Open-source Halloween! Here's a spooky light show. Just `pip install blessings` and then run the script in any terminal. At the moment, it rotates between lightning-like flashes in various colors and gentle gradient pulsing. Put it in a window with the blinds down, and it diffuses nicely. Laptops are bright! Contribute your own effects in the co…
#!/usr/bin/env python
from itertools import chain
import random
from random import randint
from time import sleep, time
from blessings import Terminal
t = Terminal()
@erikrose
erikrose / git-review
Created September 26, 2013 17:02
I made myself a "git review" subcommand which takes a user:branch pair pasted from a pull request page, like abbeyj:macro-use-extents, and does the fetch and checkout to get me ready to try it out. It's like 2 lines, but it's remarkable the mental weight it lifts. I no longer dread reviews. Just stick it in a file called "git-review" (no extensi…
#!/usr/bin/env python
from subprocess import check_output
from sys import argv
def main():
user, branch = argv[1].split(':')
check_output('hub fetch %s' % user, shell=True)
check_output('git checkout %s/%s' % (user, branch), shell=True)
print 'Now reviewing %s:%s.' % (user, branch)
  • Basic JS analysis for DXR
  • Index multiple trees (starting with comm-central and mozilla-aurora, the most commonly used ones on MXR)
  • Flexible, CORRECT deployment framework for DXR and others, to be factored out as Shiva. Goals: https://github.com/erikrose/shiva/tree/fast-burn#shiva
  • Socorro or L10n or other team priorities
@dstufft makes the point that fred==1.0.1 could represent fred…tar.gz,
fred…zip, or fred…wheel, etc. Right now, we don't care about the extension; we
just extract the package name from the downloaded file by means of a cheesy
heuristic. But what if an index entry makes available both a zip and a tarball?
Which does pip favor? With the current syntax, we support only a single hash. I
suppose we could count on pip keeping its format-favoring behavior stable over
time. Are we going to have a problem here?
>>> from json import dumps
>>> u = u'jörg'
>>> e = u.encode('utf-8')
>>> dumps(u)
'"j\\u00f6rg"'
>>> dumps(e)
'"j\\u00f6rg"'