Skip to content

Instantly share code, notes, and snippets.

View amcgregor's full-sized avatar
🏢
I died! …well, I got better…

Alice Zoë Bevan–McGregor amcgregor

🏢
I died! …well, I got better…
View GitHub Profile
@liamcurry
liamcurry / gist:2597326
Created May 4, 2012 19:56
Vanilla JS vs jQuery

Moving from jQuery

Events

// jQuery
$(document).ready(function() {
  // 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.
@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…)

@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
@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"
@cowboy
cowboy / HEY-YOU.md
Last active February 27, 2025 12:24
jQuery Tiny Pub/Sub: A really, really, REALLY tiny pub/sub implementation for jQuery.
@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