This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- query with stored plan | |
CREATE or replace FUNCTION pybench1(id int) RETURNS text AS ' | |
if (SD.has_key("plan")): | |
plan = SD["plan"] | |
else: | |
plan = plpy.prepare("SELECT * FROM pagetimer pt, pagebrowser pb WHERE pt.idtimer = $1 and pt.idtimer = pb.idtimer", ["int4"]) | |
SD["plan"] = plan | |
rec = plpy.execute(plan, [id]) | |
if (rec.nrows() > 0): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def z_get_string_dist(self): | |
cmd=""" | |
DROP TYPE IF EXISTS string_dist_results cascade; | |
CREATE TYPE string_dist_results as ( | |
idx integer, | |
orig_str text, | |
jaro double precision, | |
jaro_b text, | |
leven integer, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create or replace function update_asset_json(text, text, integer) returns setof integer as $$ | |
import simplejson | |
from datetime import datetime | |
now = datetime.now() | |
updated_data = simplejson.loads(args[1]) | |
rs = plpy.execute("select id, data from assets where id in (%s)" % args[0]) | |
resp = [] | |
for r in rs: | |
data = simplejson.loads(r['data']) | |
data.update(updated_data) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION set_seq_vals(schema_name TEXT) | |
RETURNS TEXT[] | |
AS $$ | |
schemaname = schema_name if schema_name else 'public' | |
plpy.execute("SET SEARCH_PATH=%s,public" % schemaname) | |
tables = plpy.execute("SELECT tablename FROM pg_tables WHERE schemaname = '%s'" % schemaname); | |
altered_seqs = [] | |
for t in tables: | |
cols = plpy.execute("SELECT column_name, column_default, data_type, is_nullable FROM information_schema.columns WHERE table_name = '%s' AND data_type in ('integer', 'bigint') AND column_default IS NOT NULL" % t["tablename"]) | |
for c in cols: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION run_server() RETURNS text | |
LANGUAGE plpythonu STRICT | |
AS $$ | |
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer | |
class PGHandler(BaseHTTPRequestHandler): | |
def do_GET(self): | |
plpy.notice("Path: %s" % self.path) | |
if self.path.count('/') == 2 and self.path.split('/')[1] != "" and self.path.split('/')[2] != "": | |
nsp = plpy.quote_ident(self.path.split('/')[1]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION download(url TEXT) RETURNS TEXT | |
AS $$ | |
import urllib2 | |
try: | |
result = urllib2.urlopen(url) | |
rawdata = result.read() | |
info = result.info() | |
try: | |
content_type, encoding = info['Content-Type'].split('charset=') | |
except: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DROP FUNCTION IF EXISTS get_role_to_actor_and_actor_to_role( INOUT BIGINT, OUT JSONB, OUT JSONB ); | |
CREATE OR REPLACE FUNCTION get_role_to_actor_and_actor_to_role( | |
INOUT program_id BIGINT, | |
OUT actor_to_role JSONB, | |
OUT role_to_actor JSONB) | |
RETURNS RECORD IMMUTABLE | |
AS $plpython_function$ | |
import json | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Haproxy config file for SSL and basic authentication | |
# | |
# Since ssl is needed, we need to use | |
# `make TARGET=linux26 USE_OPENSSL=1 ADDLIB=-lz` to install haproxy. | |
# Also, haproxy version must be haproxy-1.5-dev19 or above. | |
# | |
# An example curl command that queryies pic-collage.com/api/collages/feed is | |
# `curl -k -v -u 'collages:password' 'https://ec2-ip.compute-1.amazonaws.com/api/collages/feed'` | |
userlist collages_dyno |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# vim: ft=python ts=4 sw=4 expandtab | |
# | |
# Copyright (c) 2013 Reed Kraft-Murphy <[email protected]> | |
# | |
# Permission is hereby granted, free of charge, to any person obtaining a copy | |
# of this software and associated documentation files (the "Software"), to deal | |
# in the Software without restriction, including without limitation the rights | |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
# copies of the Software, and to permit persons to whom the Software is |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo yum install gcc python27 python27-devel postgresql-devel | |
sudo curl https://bootstrap.pypa.io/ez_setup.py -o - | sudo python27 | |
sudo /usr/bin/easy_install-2.7 pip | |
sudo pip2.7 install psycopg2 |