Skip to content

Instantly share code, notes, and snippets.

View luhn's full-sized avatar

Theron Luhn luhn

View GitHub Profile
@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:
#!/bin/sh
set -e
touch /tmp/linked
ln -s /tmp/linked . || true
cat <<EOF > Dockerfile
FROM busybox:ubuntu-14.04
ADD . /data
@luhn
luhn / query.json
Created January 13, 2016 17:19
Elasticsearch query
{
"query": {
"filtered": {
"filter": {
"and": [
{
"term": {
"deleted": false
}
},
(function() {
// Inspired by http://informationandvisualization.de/blog/box-plot
d3.box = function() {
var width = 1,
height = 1,
duration = 0,
domain = null,
value = Number;
showLabels = true, // whether or not to show text labels