Skip to content

Category Archives: Code Fragment

Porting Tornado to D

The other day I started porting the Tornado web server to D. I just got the IO Loop part ported. I’m planning on using this in my web framework Rootin Tootin.
You can check out the code on Launchpad: http://launchpad.net/dornado. Next I will add proper Epoll and the HTTP part. But in the meantime, you can [...]

Python: Find objects of a certain type in memory

This code snippet will allow you to look for objects of a certain type in memory. This is very useful for plugins:

"""
This looks through all the objects in memory, to find ones
of the designated type.
"""
 
import gc
 
class Animal(object):
def make_noise(self):
[...]

Code Fragment: How to programatically get MySQL table relationships

This magical chunk of goodness will allow you to query a mysql database to determine what table fields are foreign keys, and what they reference. Just replace ‘database_name’ and ‘table_name’ with the respective names you want:

1
2
3
4
5
6
7
SELECT column_name, referenced_table_name,
referenced_column_name
FROM information_schema.key_column_usage
WHERE table_schema=’database_name’
AND table_name=’table_name’
AND referenced_table_name IS NOT NULL
AND referenced_column_name IS NOT NULL;