Skip to content

Instantly share code, notes, and snippets.

View themiurgo's full-sized avatar
🎯
Focusing

Antonio Lima themiurgo

🎯
Focusing
View GitHub Profile
@themiurgo
themiurgo / convert_all_gzipped.sh
Created September 25, 2012 13:36
Convert a one-line stream of JSON objects into a newline separated (multiline) stream
#/bin/bash
# Fix all the files and puts them in a 'fixed' subdirectory
mkdir fixed
for f in *.gz; do gunzip -c $f | ruby jsonsm.rb | gzip -c > fixed/$f; done
@themiurgo
themiurgo / geocoder.py
Created July 18, 2012 13:27
A Google Geocoder with a MongoDB memoizer. For the ratelim module, look at https://gist.github.com/3006305
import collections
import time
import requests
import pymongo
import ratelim
import textwrap
G_GEO_SUCCESS = 200
G_GEO_SERVER_ERROR = 500
G_GEO_MISSING_QUERY = 601
@themiurgo
themiurgo / elapsed_since_last_update.sh
Created June 29, 2012 15:54
Seconds elapsed since last update of a file
# FILL FILENAME
# Return the seconds from last modification of a file, among a list of files
file=$(ls FILENAME -hant --time-style +%s | head -n1 | awk '{print $6}' ) ; now=$(date +%s); echo $((now-file))
@themiurgo
themiurgo / ratelim.py
Created June 27, 2012 19:40
Rate limit decorator
import time
import datetime
class rate_limited(object):
def __init__(self, max_calls, time_interval):
assert max_calls > 0
assert time_interval > 0
self.__last_reset = None
self.__max_calls = max_calls
self.__time_interval = time_interval # seconds