Skip to content

Instantly share code, notes, and snippets.

@decibel
decibel / default.py
Created April 5, 2016 23:35
Simple python function to return a default value depending on the data type
def clear(i):
if isinstance(i, basestring):
return ''
elif isinstance(i, int):
return 0
elif isinstance(i, float):
return 0.0
elif i is None:
return None
elif isinstance(i, dict):
#!/bin/bash
# Based on https://gist.github.com/petere/6023944
set -eux
sudo apt-get update
packages="python-setuptools postgresql-$PGVERSION postgresql-server-dev-$PGVERSION postgresql-common"
@decibel
decibel / gist:7c5fdb4a26b89087fb0e
Created January 14, 2016 22:18
Simple procedure for setting defaults on new schemas
/*
* Assumes that applications connect as 'my_project__blah' and that you've done GRANT my_project__app to my_project__blah.
* Also assumes that select_roles is a list of groups, like "my_project__dev", "my_project__read_only", etc.
*/
CREATE FUNCTION ddl_tools.schema__defaults(
schema_name name
, select_roles text
) RETURNS void LANGUAGE plpgsql AS $body$
DECLARE
select_template CONSTANT text := $template$
@decibel
decibel / lambda.sql
Last active December 31, 2015 21:39
CREATE OR REPLACE FUNCTION lambda(
code text
, VARIADIC inputs anyarray
) RETURNS anyelement LANGUAGE plpgsql AS $body$
DECLARE
c_prefix CONSTANT text := 'lambda_function_';
c_pattern CONSTANT text := '^' || c_prefix || '([0-9]+)$';
fname text;
foid regprocedure;
fargs regtype[];