Skip to content

Instantly share code, notes, and snippets.

@pilgrim2go
pilgrim2go / plpython_returning_record.py
Created October 27, 2016 11:29 — forked from happysundar/plpython_returning_record.py
Example of a PLPythonU method that returns a record
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
@pilgrim2go
pilgrim2go / haproxy.cfg
Created November 8, 2016 07:35 — forked from fumin/haproxy.cfg
Haproxy config file for SSL and basic authentication
# 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
@pilgrim2go
pilgrim2go / filerotator.py
Created November 9, 2016 07:54 — forked from adejones/filerotator.py
Python class and utility for file rotation. Configurable daily, weekly and monthly retention; can use hard links to save space; supports `argparse` config files.
#!/usr/bin/env python3
# vim: ft=python ts=4 sw=4 expandtab
#
# Copyright (c) 2013 Reed Kraft-Murphy <reed@reedmurphy.net>
#
# 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
@pilgrim2go
pilgrim2go / install-psycopg2.sh
Created November 9, 2016 10:23 — forked from whyvez/install-psycopg2.sh
install psycopg2 on aws linux
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
@pilgrim2go
pilgrim2go / etlutils.py
Created November 9, 2016 10:33 — forked from KarolBedkowski/etlutils.py
petl - utils (csv-unicode, xml)
import csv
from xml.etree import ElementTree
from petl import tocsv, fromcsv, convertall
def tocsvunicode(table, filename, encoding='utf-8', **kwds):
data = (map(lambda x: unicode(x).encode(encoding), row) for row in table)
tocsv(data, filename, **kwds)
def fromcsvunicode(source=None, dialect=csv.excel, encoding='utf-8', **kwargs):
table = fromcsv(source, dialect, **kwargs)
@pilgrim2go
pilgrim2go / build.sh
Created November 14, 2016 06:03 — forked from bryantrobbins/build.sh
Running a packer build which pushes an nginx-based image of a static website AWS ECR
#!/bin/bash -v
# Add your app build steps here
# Assume that these steps produce a "dist" folder at this level
# Prepare packer variables
repoName=$1
imageVersion=$2
chmod 700 fetch.sh
./fetch.sh $repoName $imageVersion > variables.json
# coding=UTF-8
from __future__ import division
import nltk
import re
import requests
# Add your freebase key here
# If you don't have one, register at https://code.google.com/apis/console
FREEBASE_KEY = ""
@pilgrim2go
pilgrim2go / example1.py
Created December 1, 2016 07:49 — forked from onyxfish/example1.py
Basic example of using NLTK for name entity extraction.
import nltk
with open('sample.txt', 'r') as f:
sample = f.read()
sentences = nltk.sent_tokenize(sample)
tokenized_sentences = [nltk.word_tokenize(sentence) for sentence in sentences]
tagged_sentences = [nltk.pos_tag(sentence) for sentence in tokenized_sentences]
chunked_sentences = nltk.batch_ne_chunk(tagged_sentences, binary=True)
@pilgrim2go
pilgrim2go / ec2.py
Created January 3, 2017 06:55 — forked from iMilnb/ec2.py
AWS EC2 simple manipulation script using python and boto3
#!/usr/bin/env python
# Simple [boto3](https://github.com/boto/boto3) based EC2 manipulation tool
#
# To start an instance, create a yaml file with the following format:
#
# frankfurt:
# - subnet-azb:
# - type: t2.micro
# image: image-tagname
#!/usr/bin/env python
import argparse, getpass
class Password(argparse.Action):
def __call__(self, parser, namespace, values, option_string):
if values is None:
values = getpass.getpass()
setattr(namespace, self.dest, values)