Skip to content

Instantly share code, notes, and snippets.

# How to use PG Point type in SQAlchemy
#
# Most of the code comes from here:
# http://initd.org/psycopg/docs/advanced.html#adapting-new-types
import re
import sqlalchemy
import psycopg2
from psycopg2.extensions import adapt, register_adapter, AsIs
import sys
import tornado.ioloop
import psycopg2
import psycopg2.extensions
io_loop = tornado.ioloop.IOLoop.instance()
conn = psycopg2.connect('dbname=mytest user=lbolla password=secret')
conn.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
all: go.so
go.o: go.c
gcc -std=c99 -c -fPIC go.c -o go.o
go.so: go.o
gcc -shared -Wl,-soname,libgo.so -o libgo.so go.o
[MyDB]
Description = My Database
Driver = FreeTDS
Servername = W7WS6CL832J # MSSQL server name
Database = mydb
UID = username
PWD = password
Port = 1433
Charset = UTF-8
@lbolla
lbolla / par.py
Last active January 1, 2016 05:19
Python GIL and Cython
from threading import Thread
def busy_sleep(n):
while n > 0:
n -= 1
N = 99999999
t1 = Thread(target=busy_sleep, args=(N, ))
@lbolla
lbolla / process_manager.py
Created January 17, 2014 15:17
Class to manage long running processes, restarting them when necessary
import concurrent.futures
class ProcessManager(object):
def __init__(self):
self.pool = concurrent.futures.ProcessPoolExecutor()
self.futures = {}
def submit(self, f, *args, **kwargs):
@lbolla
lbolla / zombies.py
Last active May 1, 2021 15:43
Killing zombies
import os
import time
from subprocess import Popen
def check_zombies(expected_nzombies):
# NOTE: don't use Popen() here
output = os.popen(r"ps aux | grep ' Z' | grep -v grep").read()
got_nzombies = len(output.splitlines())
if got_nzombies > 0:
import random
import string
import cherrypy
class StringGenerator(object):
@cherrypy.expose
def index(self):
return """<html>
import StringIO
import cPickle
small = [{i: i} for i in xrange(9)]
medium = [{i: i} for i in xrange(999)]
large = [{i: i} for i in xrange(999999)]
def dumps(obj):
return cPickle.dumps(obj)
(flycheck-define-checker javascript-flow
"A JavaScript syntax and style checker using Flow.
See URL `http://flowtype.org/'."
:command ("flow" source-original)
:error-patterns
((error line-start
(file-name)
":"
line