Skip to content

Instantly share code, notes, and snippets.

@pbdeuchler
pbdeuchler / psql_bootstrap.sh
Created April 22, 2020 00:34
Bootstraps a postgres server with a database and read/write user
#!/bin/bash -eu
# Run command: PROJECT_NAME=test RW_PASSWORD=test HOSTNAME=127.0.0.1 ./psql_bootstrap
psql -h $HOSTNAME --username=postgres -c 'DROP DATABASE IF EXISTS '"${PROJECT_NAME}"';'
psql -h $HOSTNAME --username=postgres -c 'DROP USER IF EXISTS '"${PROJECT_NAME}"'_rw;'
psql -h $HOSTNAME --username=postgres -c 'CREATE DATABASE '"${PROJECT_NAME}"';'
psql -h $HOSTNAME --username=postgres -c 'CREATE USER '"${PROJECT_NAME}"'_rw WITH PASSWORD '"'${RW_PASSWORD}'"';'
psql -h $HOSTNAME --username=postgres -c 'GRANT ALL PRIVILEGES ON DATABASE '"${PROJECT_NAME}"' TO '"${PROJECT_NAME}"'_rw;'

Keybase proof

I hereby claim:

  • I am pbdeuchler on github.
  • I am pbdeuchler (https://keybase.io/pbdeuchler) on keybase.
  • I have a public key whose fingerprint is 479B FD51 D7AC 441D 0439 06CD 44BD 3E79 6C93 5180

To claim this, I am signing this object:

@pbdeuchler
pbdeuchler / adaptive_resize.py
Created May 22, 2014 19:13
Adaptive resize for avatars using Python and PIL/Pillow, square crop from center plus an optional resizing
def adaptive_resize(img, size=None): #img is a PIL/Pillow Image object, size is a tuple of desired dimensions
if size is not None: # resize image
if size[0] != size[1]:
raise Exception("Provided target dimensions must be equal")
smallest_side = min(img.size[0], img.size[1])
if size[0] < smallest_side: # make sure we actually need to resize
resize_ratio = float(size[0]) / float(smallest_side)
resize_x = int(math.floor(img.size[0] * resize_ratio))
resize_y = int(math.floor(img.size[1] * resize_ratio))
img = img.resize((resize_x, resize_y))
@pbdeuchler
pbdeuchler / map.go
Created July 16, 2013 02:24
Proof of concept Go map function
package main
import (
"fmt"
"strconv"
"reflect"
)
type mapFunc func(interface{}) (interface{})
@pbdeuchler
pbdeuchler / gist:4066816
Created November 13, 2012 16:35
Read Only Site Flag for Django (Request Processor)
def read_only_processor(request):
if read_only_flag():
if request.method in ['GET', 'HEAD']:
return {
'read_only': True,
'error_message': 'Sorry, this site is read only right now!"
}
else:
#return a "Read only" response
else:
@pbdeuchler
pbdeuchler / main.py
Created February 22, 2012 19:01
CSCI 345 Project 1
import shelve
import os
import sys
#Global vars
SHELF = os.getcwd() + '/' +'store' #variable for db name
LOC = os.getcwd() + '/files/' #variable for corpus location (os.getcwd() gets the current directory)
write = sys.stdout.write #For progress bar
db = {}
@pbdeuchler
pbdeuchler / gist:1056826
Created June 30, 2011 18:16
A sample SkyBot Module for polling support alerts
#!/usr/bin/python -tt
'''
Didn't you hear? The bird is the word!
@author: Philip Deuchler
@version: 0.2 Beta
'''
import urllib2
import json
import web
@pbdeuchler
pbdeuchler / gist:1049792
Created June 27, 2011 20:44
A JSON PUT request made by SkyBot upon rule recognition
{
"number": "3",
"body": "i feel pretty",
"author": "voxeobob",
"chat": "Voxeo Engineering",
"time": "1309211072"
}
@pbdeuchler
pbdeuchler / gist:1049551
Created June 27, 2011 19:02
Valid JSON POST request for SkyBot
{
"name": "test",
"ip": "172.16.160.101",
"port": "8080",
"protocol": "rest",
"version": "0.2"
"rules": {
"1": [
"string",
"chatname"
@pbdeuchler
pbdeuchler / gist:1045428
Created June 24, 2011 19:02
Python ReST interface
import web
import json
from mimerender import mimerender
#Render statements
render_xml = lambda message: '<message>%s</message>' % message
render_json = lambda **args: json.dumps(args)
render_html = lambda message: '<html><body>%s</body></html>' % message
render_txt = lambda message: message