Skip to content

Instantly share code, notes, and snippets.

@mdellavo
mdellavo / fdb-mapper.py
Last active January 16, 2024 15:45
WIP: Document mapper for FoundationDB
import dataclasses
import datetime
import itertools
import struct
from typing import TypeVar, Optional, Any, Type, TypedDict
import fdb
from fdb.impl import Transaction
from fdb.subspace_impl import Subspace
@mdellavo
mdellavo / python-zmq-workers.py
Created June 12, 2012 17:21
python-zmq-worker-queue
import zmq
import logging
import uuid
MASTER_ENDPOINT = 'tcp://127.0.0.1:5000'
WORKER_ENDPOINT = 'tcp://127.0.0.1:5001'
log = logging.getLogger(__name__)
TASKS = {}
@mdellavo
mdellavo / jquery.errors.js
Created August 29, 2011 17:54
JQuery plugin to add error messages to form elements from an object.
(function($) {
$.fn.clearErrors = function() {
this.find('.error').removeClass('error');
this.find('.error-message').remove();
}
$.fn.addErrors = function(errors) {
var $this = this;
@mdellavo
mdellavo / convert-pgp-to-ssh.sh
Created September 15, 2016 13:33
Convert PGP Public Key to OpenSSH
# import the public key
gpg --import ../alice.asc
gpg --export $KEYID | openpgp2ssh $KEYID
@mdellavo
mdellavo / gtfs.py
Created March 22, 2012 15:37
SQLAlchemy GTFS Models
from sqlalchemy import create_engine, Column, Integer, String, DateTime, \
Boolean, Unicode, Numeric as _Numeric, Date, Time, ForeignKey, Table, and_, \
create_engine
from sqlalchemy.orm import sessionmaker, scoped_session, relation, class_mapper
from sqlalchemy.orm.collections import attribute_mapped_collection
from sqlalchemy.orm.properties import ColumnProperty, RelationshipProperty
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm.exc import NoResultFound
from sqlalchemy.ext.associationproxy import association_proxy
from sqlalchemy.types import TypeDecorator
@mdellavo
mdellavo / django-reverse-with-query-params.py
Created March 22, 2012 14:11
Django shortcut to generate a url w/ query params (for serious)
def reverse_with_queryparams(view, *args, **kwargs):
return reverse(view, args=args) + '?' + urllib.urlencode(kwargs)
@mdellavo
mdellavo / taskpool.py
Created April 24, 2017 00:28
asyncio task pool
import asyncio
from asyncio.queues import Queue
TERMINATOR = object()
class TaskPool(object):
def __init__(self, loop, num_workers):
self.loop = loop
self.tasks = Queue(loop=self.loop)
eval "$(pyenv init --path 2>/dev/null)"
eval "$(pyenv init - 2>/dev/null)"
eval "$(pyenv virtualenv-init - 2>/dev/null)"
export PS1='($(pyenv version-name)) '$PS1
export GIT_PS1_SHOWDIRTYSTATE=true
export GIT_PS1_SHOWCOLORHINTS=true
if [ -f /usr/local/etc/bash_completion.d/git-prompt.sh ]; then
source /usr/local/etc/bash_completion.d/git-prompt.sh
@mdellavo
mdellavo / arch-aarch64-install-raspberry-pi.md
Last active December 16, 2021 01:51
Prepare an ArchLinux Image for a Raspberry Pi
@mdellavo
mdellavo / gist:1070957
Created July 8, 2011 02:03
redis-blocking-queue.py
# poller.py
import redis
import time
# under an evented wsgi server, a queue can be assigned to a response app_iterable
# to return a long-polling chunked response
def queue():
store = redis.Redis('localhost')
while True: