This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
API_KEY = "" # FILL THIS | |
class Geocoder(object): | |
endpoint = "http://www.mapquestapi.com/geocoding/v1/batch" | |
endpoint = "http://open.mapquestapi.com/geocoding/v1/batch" | |
def __init__(self, api_key): | |
self.api_key = api_key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from json import load, JSONEncoder | |
from argparse import ArgumentParser, FileType | |
from re import compile | |
import sys | |
float_pat = compile(r'^-?\d+\.\d+(e-?\d+)?$') | |
charfloat_pat = compile(r'^[\[,\,]-?\d+\.\d+(e-?\d+)?$') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
#-*- coding: utf-8 -*- | |
"""This script was used to generate random test files for the course | |
of Computer Networks 2014 at University of Birmingham, Computer Science. | |
Author: Antonio Lima | |
License: WTFPL | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
import os | |
from collections import namedtuple | |
def read_csv(fname, tabname=None, names=None, headers=True): | |
with open(fname, "r") as fobj: | |
if not tabname: | |
full_basename = os.path.basename(fname) | |
basename, ext = os.path.splitext(full_basename) | |
tabname = basename.capitalize() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import json | |
import itertools | |
fnames = sys.argv[1:] | |
jsons = [(json.loads(i) for i in open(fname)) for fname in fnames] | |
def paste(iterables): | |
for docs in itertools.izip_longest(*iterables, fillvalue={}): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def embed(fmaps, width='100%', height='510px', *args, **kwargs): | |
""" | |
Embeds a folium map in a IPython/Jupyter notebook. | |
This method will not work if the map depends on any files (json data). Also this uses | |
the HTML5 srcdoc attribute, which may not be supported in all browsers. | |
fmaps -- a single folium map or an iterable containing folium maps | |
""" |
OlderNewer