Skip to content

Instantly share code, notes, and snippets.

@evz
evz / README.md
Created October 7, 2012 21:43
S3 Publisher for Hyde (static site generator written in Python)

How to use

  • Add the s3.py file to your project. As an example, put it inside a folder called publishers.
  • The folder where s3.py resides must be a Python package, so add an empty __init__.py file to that folder also.
  • Add the following configuration to your site.yaml and modify it as needed:
publisher:
    s3:
 type: publishers.s3.S3 # here, publishers is the folder where the s3.py file was placed
@evz
evz / recode
Last active May 11, 2020 11:17
Re encode all files in a directory tree. (requires recode)
# Find encoding
find . -type f | xargs -0 -I {} echo "{}" | xargs -I {} file -bi {}
# Re-encode
find . -type f | xargs -0 -I {} echo "{}" | xargs -I {} recode ISO-8859-1..UTF-8 {}
@evz
evz / load_data.py
Created March 10, 2016 22:27
Faster loader for open ee meter datastore
import csv
import sqlalchemy as sa
import os
import pytz
from datetime import datetime
import itertools
tz = pytz.timezone('America/Chicago')
# DB_CONN = os.environ['DATABASE_URL']
@evz
evz / LoadData.py
Created October 29, 2011 17:42
Making maps 101 - a few things I've picked up
#!/usr/bin/env python
# For this script to work you must set the Django settings file
# as an environment setting before importing LayerMapping
# Alternatively you can place
# export DJANGO_SETTINGS_MODULE=settings
# in your .bash_profile
# or paste this code into a $ manage.py shell
import multiprocessing
import time
class ChildThread(multiprocessing.Process):
def __init__(self, stopper, counter, **kwargs):
super().__init__(**kwargs)
self.stopper = stopper
self.counter = counter
def run(self):
@evz
evz / sql_alchemy_demo.py
Created August 5, 2016 15:24
SQL Alchemy demo
import sqlalchemy as sa
from sqlalchemy.orm import create_session
engine = sa.create_engine('postgresql://localhost:5432/dedupeapi')
db_session = create_session(bind=engine,
autocommit=False,
autoflush=False)
@evz
evz / lead_tests.py
Created July 5, 2016 15:01
Download and extract data about CPS lead tests
import subprocess
import sys
from io import StringIO
import csv
if __name__ == "__main__":
proc = subprocess.Popen(['java',
'-jar',
'../tabula-java/target/tabula-0.9.0-jar-with-dependencies.jar',
{
"distinct": [
[
{
"payer_address": "950 f. street nw, suite 300, washington, dc, 20004",
"payer_name": "pharmaceutical research & manufacturers of america (phrma)",
"record_id": 500
},
{
"payer_address": "950 e paces ferry rd ne, ste 2450, atlanta, ga, 30326",
@evz
evz / trees.py
Created February 9, 2016 21:02
Edgelist to Tree
if __name__ == "__main__":
import pprint
import copy
engine = init_engine(DB_CONN)
children = [(1,2),(1,3),(2,4)]
edgelist = engine.execute(children)
@evz
evz / csv2html.py
Last active December 20, 2015 18:48
Take a CSV and make it an HTML table
import csv
def table_it(fname):
outs = '<table id="abms" class="dataTable" aria-describedby="abms_info">'
with open(fname, 'rb') as f:
reader = csv.reader(f)
headers = reader.next()
outs += '<thead><tr>'
outs += ''.join(['<th>%s</th>' % h for h in headers])
outs += '</tr></thead><tbody>'