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
# -*- coding: utf-8 -*-
"""
Base asset model from the original prototype of Contentment.
"""
import logging, re
from uuid import UUID, uuid4
@amcgregor
amcgregor / worker.py
Last active August 29, 2015 14:07
An operational RPC worker for MongoDB.
#!/usr/bin/env python
# coding: utf-8
"""MongoDB queue and RPC mechanism for remote deferred execution.
To get started with this, create a virtualenv:
virtualenv --python=python2.7 q
cd q
source bin/activate
@amcgregor
amcgregor / lolshadowbanned.md
Last active August 29, 2015 14:07
On how the “secretary of the office of the president” retained me as a Rogers client.

So your network doesn't support e-mail, eh?

On how the “secretary of the office of the president” retained me as a Rogers client.

I've been a long-long-long-time Rogers customer. Their support, for me, usually gets to the point not of desperation, but of joy. Admittedly it usually takes several attempts to reach someone who isn't a complete idiot reading from a script, but I've always been satisfied in the end. Satisfied enough to remain a customer, at least! This event in the mid 00's, though, taxed the limits I'm willing to reach for bad tech support while still managing to leave me as a customer. (Lesser of evils and whatnot.)

I'm a sysop. I need access to my boxen from anywhere and everywhere, and while GSM speeds are pretty suck compared to modern LTE it was more than enough for an SSH connection, or some light-weight HTTP or VNC/RDP over a VPN. The VPN turned out to be a sticking point, as no matter which technology (PPTP, L2TP/IPsec, etc.) I tried my phone would never connect and/or authent

@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 / 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 / _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

@grayghostvisuals
grayghostvisuals / scrollmation
Last active July 12, 2016 14:28
Anchor Scroll w/Vanilla JS (also displays hash value)
var scrollmation_parent = document.getElementById(parent_el).nextElementSibling;
var easing = {
linear: function (t) { return t; },
easeInQuad: function (t) { return t*t; },
easeOutQuad: function (t) { return t*(2-t); },
easeInOutQuad: function (t) { return t < 0.5 ? 2*t*t : -1+(4-2*t)*t; },
easeInCubic: function (t) { return t*t*t; },
easeOutCubic: function (t) { return (--t)*t*t+1; },
easeInOutCubic: function (t) { return t < 0.5 ? 4*t*t*t : (t-1)*(2*t-2)*(2*t-2)+1; },
@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…)

@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"