Skip to content

Instantly share code, notes, and snippets.

View FSX's full-sized avatar
💭
I may be slow to respond.

Frank FSX

💭
I may be slow to respond.
View GitHub Profile
@FSX
FSX / async_psycopg2.py
Created March 8, 2011 22:11
A module for asynchronous PostgreSQL queries in Tornado.
#!/usr/bin/env python
__author__ = 'Frank Smit <frank@61924.nl>'
__version__ = '0.1.0'
import functools
import psycopg2
from tornado.ioloop import IOLoop, PeriodicCallback
@FSX
FSX / forms.py
Created May 7, 2011 14:07
Making use of Tornado's locale functionality in WTForms. By Ben Darnell.
import tornado.locale
from wtforms import Form, TextField, PasswordField, SubmitField, validators
# Later use e.g. FORMS['es'].LoginForm
FORMS = {}
error_msgs = (
'You must enter a username.',
@FSX
FSX / example.js
Created May 25, 2011 16:20
Small jQuery plugin that "ajaxifies" your page ans uses the HTML5 hisory API.
jQuery.ajaxify({
'content-id' : '#main-content',
'animation': [{opacity: 0}, {opacity: 1}],
'duration': 200,
'callback' : function() {
// Some function you want to execute after the new page has been loaded
}
});
@FSX
FSX / benchmark.py
Created August 23, 2011 21:54
Ctypes port of Misaka (https://github.com/FSX/misaka)
import time
import os.path as path
import misaka
import misaka_ctypes
class Benchmark(object):
def __init__(self, name):
self._name = name
@FSX
FSX / ExampleTest.php
Created November 13, 2011 21:39
Simple unit testing library for PHP.
<?php
class ExampleTest extends TestLibTestCase
{
protected $name = 'utf8\len()';
public function test_equal()
{
$this->is_equal('test', 'test');
}
#!/usr/bin/env python2
"""
Reads a Genbank file line by line.
"""
import re
from pprint import pprint
@FSX
FSX / ircbot.py
Created December 20, 2011 21:14
A very simple IRC bot. It does nothing.
import re
import socket
from tornado import ioloop
from tornado import iostream
RE_ORIGIN = re.compile(r'([^!]*)!?([^@]*)@?(.*)')
@FSX
FSX / umeko.py
Created March 15, 2012 14:55
Tornado + Redis demo.
import socket
from itertools import imap
from functools import partial
from collections import deque
from tornado import ioloop
from tornado import iostream
import hiredis
@FSX
FSX / example.py
Created April 30, 2012 22:09
Small unit testing module.
# From https://github.com/FSX/misaka/blob/master/tests/misaka_test.py
import re
import codecs
from os import path
from glob import glob
from subprocess import Popen, PIPE, STDOUT
from minitest import TestCase, ok, runner
@FSX
FSX / tornado_thread_pool.py
Created May 2, 2012 16:02
A simple thread pool for Tornado.
#!/usr/bin/env python
# Thread pool based on: http://code.activestate.com/recipes/577187-python-thread-pool/
from queue import Queue
from threading import Thread
from functools import partial
import tornado.httpserver
import tornado.ioloop
import tornado.options