Skip to content

Instantly share code, notes, and snippets.

View jmoiron's full-sized avatar

Jason Moiron jmoiron

View GitHub Profile
+++ Statistics Dump +++ (1393879884)
++ Incoming Requests ++
7122195 QUERY
1 IQUERY
4 STATUS
1 NOTIFY
++ Incoming Queries ++
5189989 A
81035 NS
1754 CNAME
func ReadAll(r io.Reader) ([]byte, error)
func LoadGzippedJSON(r io.Reader, v interface{}) error {
data, err := ioutil.ReadAll(r)
if err != nil {
return err
}
// oh wait, we need a Reader again..
raw := bytes.NewBuffer(data)
unz, err := gzip.NewReader(raw)
if err != nil {
return err
func LoadGzippedJSON(r io.Reader, v interface{}) error {
raw, err := gzip.NewReader(r)
if err != nil {
return err
}
return json.NewDecoder(raw).Decode(&v)
}
# this is how we program for some reason
ls > files.txt
grep "foo" files.txt > grepped.txt
wc -l grepped.txt
rm files.txt grepped.txt
# github search for "json.loads(" => 210,000 matches
feed = urllib2.urlopen("http://example.com/api.json").read()
data = json.loads(feed)
# github search for "json.load(" => 58,000 matches
data = json.load(urllib2.urlopen("http://example.com/api.json"))
@jmoiron
jmoiron / synpad.py
Last active August 29, 2015 14:22
synpad
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Simple synaptics client save/restore."""
import argparse
import sys
import os.path
from collections import OrderedDict
from subprocess import *
# parallelize a function n ways, automatically spliting a big list
# of arguments into n roughly equal sized groups
import math
from multiprocessing import Pool
def split(iterable, n):
"""Splits an iterable up into n roughly equally sized groups."""
groupsize = int(math.floor(len(iterable) / float(n)))
remainder = len(iterable) % n
# twitter oauth example using urllib
#
# Many uses of the twitter api don't require authenticating as other users,
# but the documentation centers around it. In this example, we're using the
# twitter-provided access key & secret (keys['token']) rather than going
# through the handshake.
import json
import urllib2
@jmoiron
jmoiron / omlette_stats.py
Created May 5, 2011 00:04
silly stats on amit's blog
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""post stats on amit just because"""
import re
import urllib2
from lxml import html
url = 'http://omlettesoft.com/newjournal.php3?topic=On+the+Waterfront&who=Lord+Omlette'