This file contains 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
#!/bin/bash | |
# | |
# The MIT License | |
# | |
# Copyright 2014 Jakub Jirutka <jakub@jirutka.cz>. | |
# | |
# 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 |
This file contains 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
#!/bin/bash | |
# CSV to JSON converter using BASH | |
# Usage ./csv2json input.csv > output.json | |
# http://blog.secaserver.com/2013/12/convert-csv-json-bash/ | |
input=$1 | |
[ -z $1 ] && echo "No CSV input file specified" && exit 1 | |
[ ! -e $input ] && echo "Unable to locate $1" && exit 1 | |
This file contains 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
{ | |
"AWSTemplateFormatVersion": "2010-09-09", | |
"Resources": { | |
"Topic": { | |
"Type": "AWS::SNS::Topic", | |
"Properties": { | |
} | |
}, | |
"Queue": { | |
"Type": "AWS::SQS::Queue", |
This file contains 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/python2 | |
# From https://gist.github.com/iomz/9774415 | |
# Adapt to use boto3 | |
import boto3 | |
import botocore | |
from time import sleep | |
import sys | |
import os | |
if len(sys.argv) != 3: |
This file contains 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 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 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 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 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 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: |