Skip to content

Instantly share code, notes, and snippets.

View amcgregor's full-sized avatar
🏢
Examining Options

Alice Zoë Bevan–McGregor amcgregor

🏢
Examining Options
View GitHub Profile
@amcgregor
amcgregor / gist:405354
Last active June 15, 2020 16:35
Python timeit benchmarking for realistic optimizations.
# All units in usecs (µsec) comparing Python 2.7 | 3.7.
# Last updated: 2019-02-11
# MacBook Pro (15-inch, 2016)
# macOS 10.14.3
# 2.7 GHz Intel Core i7
# 16 GB 2133 MHz LPDDR3
python -m timeit "200 <= 250 < 300" # 0.0354 | 0.059
python2.7 -m timeit "250 in xrange(200, 300)" # 1.25
@cowboy
cowboy / HEY-YOU.md
Last active April 9, 2024 15:54
jQuery Tiny Pub/Sub: A really, really, REALLY tiny pub/sub implementation for jQuery.
@andreisavu
andreisavu / http_serve.py
Created November 29, 2010 11:19
Dummy HTTP server useful for testing
#!/usr/bin/env python
""" Test HTTP Server
This script starts a http server that will respond to HTTP requests
with a predefined response.
Usage:
./http_server.py --port=8080 --code=404 --content="Page not Found"
@agronholm
agronholm / reactor.py
Created January 15, 2011 04:50
reactor.py
from Queue import Queue, Empty
from socket import (socket, error, AF_INET, SOCK_STREAM, SOCK_DGRAM,
SOL_SOCKET, SOL_TCP, SO_ERROR, TCP_NODELAY)
from errno import EINPROGRESS
from select import select
from threading import current_thread
from concurrent.futures import Future
from functools import partial
import sys
import os
@amcgregor
amcgregor / 0-overview.textile
Created November 4, 2011 04:31
BDD Python DSL

What I propose below is a Behaviour (or Story) Driven Development domain-specific language for writing your tests in Python. This uses some tricks of how imports are done (via encoding) to dynamically translate the tests from the DSL into pure Python. Additional tricks are used to preserve the line numbers of errors, offer abbreviated asserts, and automatically pass local variables from parent to child scopes.

This is parallelizable for efficient test running, compiles to Python bytecode for efficiency, and follows the same style as doctests.

If you hate DSLs (hey, Python ain’t Ruby!) consider this to be a file-length docstring. If you don’t like doctests then consider this to be a template engine for tests. (Most modern template engines generate Python code…)

@amcgregor
amcgregor / 00-overview.textile
Created December 6, 2011 16:02
A high-level overview of Marrow Automaton.

Marrow Automaton

automaton |ôˈtämətən, -ˌtän|

noun ( pl. automata |-tə| or automatons ) — a moving mechanical device made in imitation of a human being.

  • A machine that performs a function according to a predetermined set of coded instructions, esp. one capable of a range of programmed responses to different circumstances.
  • A scripting infrastructure for project and system management.
@liamcurry
liamcurry / gist:2597326
Created May 4, 2012 19:56
Vanilla JS vs jQuery

Moving from jQuery

Events

// jQuery
$(document).ready(function() {
  // code
})
@frsyuki
frsyuki / my_thoughts_on_msgpack.md
Created June 11, 2012 02:36
My thoughts on MessagePack

My thoughts on MessagePack

Hi. My name is Sadayuki "Sada" Furuhashi. I am the author of the MessagePack serialization format as well as its implementation in C/C++/Ruby.

Recently, MessagePack made it to the front page of Hacker News with this blog entry by Olaf, the creator of the Facebook game ZeroPilot. In the comment thread, there were several criticisms for the blog post as well as MessagePack itself, and I thought this was a good opportunity for me to address the questions and share my thoughts.

My high-level response to the comments

To the best of my understanding, roughly speaking, the criticisms fell into the following two categories.

@amcgregor
amcgregor / _overview.textile
Last active October 7, 2015 06:18
A gentle comparison between the coverage reports for identical sample applications across two frameworks, Pyramid and WebCore 2.

The attached CSV files represent the output of the coverage.py running each of the framework’s ‘hello {name}’ examples. Each provide effectively identical example code (one using explicit route/view registration, the other using object dispatch) with absolutely no framework options enabled at all.

The results speak for themselves:

Framework Modules Compiled Executed Skipped Efficiency v. Pyr v. WC RAM
Pyramid 154 21,782 8,055 13,727 36.98% 100% 739% 20.2M
WebCore 2 39 1,938 1,089 849 56.19% 13% 100% 14.4M
@amcgregor
amcgregor / post.textile
Created July 18, 2012 02:08
On the technology of immortality.

I fully expect to be able to achieve functional immortality within my lifetime. Do not read that as plain immortality—I have little attachment to my own biology. Many argue against this on the basis of biological immortality and philosophical or physical concerns. Over-population, they say, would ruin us; immortality is unnatural the nay-sayers might quip. They might argue that no living creature is meant to live forever, despite several excellent examples of biological creatures that do live forever in a practical sense. Our life span, barring unforeseen events such as cancerous mutations or sudden impacts with a bus, is not fixed at 100 years of age. In 1900 the average life-span was just under a mere 50 years! With technology, we can do better, and have been improving steadily over time.

Let me back up for a moment and claim a specific, and I feel, realistic go