Skip to content

Instantly share code, notes, and snippets.

View jomido's full-sized avatar
🎯
Focusing

Jonathan Dobson jomido

🎯
Focusing
View GitHub Profile
from twisted.enterprise import adbapi
from twisted.python import log
import MySQLdb
class ReconnectingConnectionPool(adbapi.ConnectionPool):
"""Reconnecting adbapi connection pool for MySQL.
This class improves on the solution posted at
http://www.gelens.org/2008/09/12/reinitializing-twisted-connectionpool/
by checking exceptions by error code and only disconnecting the current
@cowboy
cowboy / HEY-YOU.md
Last active July 1, 2024 08:37
jQuery Tiny Pub/Sub: A really, really, REALLY tiny pub/sub implementation for jQuery.
@pklaus
pklaus / ping.py
Created March 5, 2011 09:50
A pure python ping implementation using raw socket.
#!/usr/bin/env python2
"""
Other Repositories of python-ping
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* https://github.com/l4m3rx/python-ping supports Python2 and Python3
* https://bitbucket.org/delroth/python-ping
@pcapriotti
pcapriotti / reactor.py
Created July 16, 2011 08:54
Reactor Framework
"""The reactor framework.
This module introduces the *reactor framework*, a collection of utilities to be
used in conjunction with the greelet library to solve the problem of inversion
of control in event-driven code.
Traditionally, writing event-driven code typically consists of "connecting"
signals to handlers (i.e. callbacks), which are to be invoked by the framework
in use when a certain "event" occurs.
@getify
getify / test.js
Created August 16, 2012 21:25
object JSON serialization that's circular-ref safe
// all this `toJSON()` does is filter out any circular refs. all other values/refs,
// it passes through untouched, so it should be totally safe. see the test examples.
// only extend the prototype if `toJSON` isn't yet defined
if (!Object.prototype.toJSON) {
Object.prototype.toJSON = function() {
function findCircularRef(obj) {
for (var i=0; i<refs.length; i++) {
if (refs[i] === obj) return true;
}
@domenic
domenic / promises.md
Last active June 24, 2024 03:11
You're Missing the Point of Promises

This article has been given a more permanent home on my blog. Also, since it was first written, the development of the Promises/A+ specification has made the original emphasis on Promises/A seem somewhat outdated.

You're Missing the Point of Promises

Promises are a software abstraction that makes working with asynchronous operations much more pleasant. In the most basic definition, your code will move from continuation-passing style:

getTweetsFor("domenic", function (err, results) {
 // the rest of your code goes here.
@matteodellamico
matteodellamico / priority_dict.py
Created January 4, 2013 10:22
Priority dict: a priority queue with updatable priorities You may have needed a priority queue with the ability to change the priorities of elements that were in the queue. This recipe solves this problem in an efficient way. The priority queue is implemented as a dictionary, where keys are the items of the queue, and values are their priorities…
# This is free and unencumbered software released into the public domain.
#
# Anyone is free to copy, modify, publish, use, compile, sell, or
# distribute this software, either in source code form or as a compiled
# binary, for any purpose, commercial or non-commercial, and by any
# means.
#
# In jurisdictions that recognize copyright laws, the author or authors
# of this software dedicate any and all copyright interest in the
# software to the public domain. We make this dedication for the benefit
@sroucheray
sroucheray / README.md
Last active December 11, 2015 15:08
A requestAnimationFrame like API which makes its best to maintain a specific framerate
import logging
import zmq
class ZmqClient (object):
def __init__(self, socket, logger):
super(ZmqClient, self).__init__()
self._logger = logger
self._socket = socket
@flying-sheep
flying-sheep / autobahn_web.py
Created January 23, 2014 18:11
Extension of the Autobahn|Python WebSocket server for HTTP
#!/usr/bin/env python3
#http://hg.python.org/cpython/file/default/Lib/test/test_asyncio
import sys
import mimetypes
from os import listdir, path as p
from argparse import ArgumentParser
from email.utils import formatdate