Skip to content

Instantly share code, notes, and snippets.

View jmoiron's full-sized avatar

Jason Moiron jmoiron

View GitHub Profile
@jmoiron
jmoiron / livescores.py
Created September 11, 2012 02:19
scrape livescores.com
#!/usr/bin/env python
# -*- coding: utf-8 -*-
""" """
import json
from urllib2 import urlopen
from lxml.html import document_fromstring
from lxml.cssselect import CSSSelector as cs
@jmoiron
jmoiron / autogobuild.sh
Created August 2, 2012 23:27
Run this script in your directory to auto build whenever you modify a golang file
#!/bin/bash
cur=`pwd`
inotifywait -mqr --timefmt '%d/%m/%y %H:%M' --format '%T %w %f' \
-e modify ./ | while read date time dir file; do
ext="${file##*.}"
if [[ "$ext" = "go" ]]; then
echo "$file changed @ $time $date, rebuilding..."
go build
@jmoiron
jmoiron / masquerade.sh
Created August 1, 2012 18:39
Toggle masquerading as a domain, forwarding configurable port to 80 (OSX and Linux)
#!/bin/bash
PORT="8000"
usage() {
cat << EOF
usage: $0 host [port]
EOF
}
@jmoiron
jmoiron / bongo.sh
Created June 30, 2012 21:58
export and import all collections from a mongodb database into/outof a single tarball
#!/bin/bash
LOADING=false
usage()
{
cat << EOF
usage: $0 [options] dbname
OPTIONS:
@jmoiron
jmoiron / attrcleaner.py
Created March 9, 2012 21:50
lxml Cleaner with attribute whitelist
#!/usr/bin/env python
from lxml.html.clean import Cleaner
from lxml.html import defs
class AttrWhitelistCleaner(Cleaner):
"""An HTML Cleaner that can use an attribute whitelist. Defaults to using
the attributes that are whitelisted by default with ``safe_attrs_only``
turned on."""
def __init__(self, **kw):
@jmoiron
jmoiron / capture.sh
Last active September 29, 2015 12:38
Script to run in compiz screenshot "launch app" to upload screenshots to my server
#!/bin/bash
# capture an area on OSX and run quickup on the produced file
CAPPATH="$HOME/tmp-capture.png"
if [ -n `which screencapture` ]; then
screencapture -i $CAPPATH
# esc exits screencapture without writing, don't try to upload in this case
@jmoiron
jmoiron / jsontest.py
Created November 2, 2011 02:00
json speed test
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Which json is the best json."""
import json
import simplejson as sjson
import ujson
import cjson
import bson
@jmoiron
jmoiron / eventlet_poc.py
Created October 25, 2011 13:36
eventlet + zmq + multiprocessing poc (similar to gevent_poc)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Simple eventlet POC to check how to get ZMQ sockets working with
subprocesses spawned by a simple process."""
import os
import eventlet
import multiprocessing
@jmoiron
jmoiron / gevent_poc.py
Created October 25, 2011 11:11
gevent + zmq + multiprocessing poc
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Simple gevent POC to check how to get ZMQ sockets working with
subprocesses spawned by a simple process."""
# this code doesn't seem to work properly; it has a
# tendency to hang at various parts of the req/rep process
# all of this stuff works flawlessly if you change:
@jmoiron
jmoiron / par2.py
Created August 30, 2011 22:06
par2header parser
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""A native python implementation of the par2 file format.
This is only intended to be able to read packets in par2, not execute
repair, verify, or create new par2 files."""
import struct