Skip to content

Instantly share code, notes, and snippets.

View luhn's full-sized avatar

Theron Luhn luhn

View GitHub Profile
#!/bin/sh
### BEGIN INIT INFO
# Provides: haproxy
# Required-Start: $local_fs $network $remote_fs
# Required-Stop: $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: fast and reliable load balancing reverse proxy
# Description: This file should be used to start and stop haproxy.
### END INIT INFO
@luhn
luhn / haproxy.initd
Last active August 29, 2015 13:56
Install HAProxy 1.5 in Ubuntu
#!/bin/sh
### BEGIN INIT INFO
# Provides: haproxy
# Required-Start: $local_fs $network $remote_fs
# Required-Stop: $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: fast and reliable load balancing reverse proxy
# Description: This file should be used to start and stop haproxy.
### END INIT INFO
@luhn
luhn / connect.py
Created July 18, 2014 15:55
txpostgres connection function (With automatic reconnect)
from psycopg2.extras import DictCursor
from txpostgres import txpostgres
from txpostgres.reconnection import DeadConnectionDetector
def db_pool_from_config(config):
"""
Create a connection pool. Returns a deferred that will fire when the
connection pool is ready.
"""
@luhn
luhn / Vagrantfile
Created July 22, 2014 15:55
Twisted #4539 failure
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# All Vagrant configuration is done here. The most common configuration
# options are documented and commented below. For a complete reference,
# please see the online documentation at vagrantup.com.
@luhn
luhn / db.py
Created October 15, 2014 19:32
Psycopg2 Connection extension
import psycopg2.extensions
class Connection(psycopg2.extensions.connection):
"""
An extension of Psycopg's connection class, to give us some additional
utilties.
"""
<?xml version="1.0" encoding="UTF-8"?>
<!--
QZ INDUSTRIES SIGNED JNLP FILE
Author:
A. Tres Finocchiaro (tres.finocchiaro@gmail.com)
Website:
http://qzindustries.com
Internal Filename:
qz-print.jar\JNLP-INF\APPLICATION.JNLP
External Filename:
@view_config(context=Forbidden, renderer='renderer.pt')
def forbidden(context, request):
# If unauthenticated, redirect to sign in
if(
Authenticated not in request.effective_principals
and request.unauthenticated_userid is None
):
raise HTTPFound('auth redirect')
# If unverified and verification would help, redirect to verification
@luhn
luhn / utils.py
Created September 21, 2015 21:58
Connection utilities for aiopg
from aiopg import Connection as BaseConnection
class Connection(BaseConnection):
async def query(self, query, args=[]):
cur = await self.cursor()
try:
await cur.execute(query, args)
return await cur.fetchall()
finally:
@luhn
luhn / gist:2381814
Created April 14, 2012 03:11
Generic Getters and Setters
class Foo(object):
def setter(var):
def set(self, value):
setattr(self, var, value+' unicorn')
return set
def getter(var):
def get(self):
return getattr(self, var)+' sasquatch'
@luhn
luhn / comprehensions.py
Last active October 3, 2015 09:37
Python one-liner
>>> [ range(x*5, x*5+5) for x in range(5) ]
[[0, 1, 2, 3, 4], [5, 6, 7, 8, 9], [10, 11, 12, 13, 14], [15, 16, 17, 18, 19], [20, 21, 22, 23, 24]]