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
“What was it when I looked at you? What power chained me through and through? What binds my heart with links so tight; I cannot live without the sight of you. What nameless thing has captured me, and made me powerless to flee? What thing is it without a name that brings my mind ere back the same, to thee. The name of love cannot apply, its commonness does not decry the haunted hunted painful cry that my heart makes for you. That ere my soul eternal makes for you.”
— True Sansha Love Letters
@amcgregor
amcgregor / string-concatenation.py
Created May 16, 2014 19:11
Testing out different methods of string concatenation.
def foo():
yield "<h"
yield "1"
yield ">"
yield "Hello world!"
yield "</h"
yield "1"
yield ">"
def bar():
class CappedQuerySet(QuerySet):
"""A cusom queryset that allows for tailing of capped collections."""
def tail(self, *q_objs, **query):
"""A generator which will block and yield entries as they are added to the collection.
Only use this on capped collections; ones with meta containing `max_size` and/or `max_documents`.
Accepts the int/float `timeout` named argument indicating a number of seconds to wait for a result.
# encoding: utf-8
from __future__ import unicode_literals, print_function
import re
from functools import partial
REPLACE = re.compile(r'[@#$]+')
# encoding: utf-8
from functools import partial
from time import sleep
from concurrent.futures import ThreadPoolExecutor, ProcessPoolExecutor
FILES = [] # Put a list of filenames here.
def work_on(fn):
with open(fn, 'rb') as fh:
# encoding: utf-8
"""Attempt to automatically resolve the configuration to use.
To use this module::
from mypackage.config import Configuration
"""
import os
# -*- 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

@signal(pre_save_post_validation)
def update_modified_timestamp(sender, document, **kw):
document.modified = datetime.utcnow()
@update_modified_timestamp
class SomeDocument(Document):
modified = DateTimeField()