Instantly share code, notes, and snippets.

# Grey Leebcse

• Sort options
Last active Dec 14, 2015
View geodesy.py
 from math import fmod, modf, sqrt, degrees, radians, sin, cos, atan2 # Mean Earth radius defined by IUGG. (Unit: meters) # ref. https://en.wikipedia.org/wiki/Earth_radius#Mean_radius EARTH_RADIUS = 6371009. def distance((lat1, lng1), (lat2, lng2)): """Get approximate geographical distance between 2 coordinates in meters.
Last active Oct 7, 2015
Python SortedList

SortedList is a list-like class that always keeps items sorted. `heaplist.SortedList` is faster than `bisectlist.SortedList` but with lesser functions.

Here are some test results:

### bisectlist.SortedList

``````Test with 10000 random numbers...
Raw list takes 1.01116704941 seconds
Raw list, sort once takes 0.00338888168335 seconds
``````
Created Apr 10, 2012
Recursively list files
View locate.py
 import os, fnmatch def locate(pattern, root=os.curdir): '''Locate all files matching supplied filename pattern in and below supplied root directory.''' for path, dirs, files in os.walk(os.path.abspath(root)): for filename in fnmatch.filter(files, pattern): yield os.path.join(path, filename) if __name__ == '__main__':
Created Feb 15, 2012
Windows Script Decoder 1.8 (Decoding JScript.Encoded)
Created Dec 7, 2011
Multimethods in Python < http://www.artima.com/weblogs/viewpost.jsp?thread=101605 >
View mm.py
 registry = {} class MultiMethod(object): def __init__(self, name): self.name = name self.typemap = {} def __call__(self, *args): types = tuple(arg.__class__ for arg in args) # a generator expression! function = self.typemap.get(types) if function is None:
Last active Sep 27, 2015
Fetch top 100 popular photos from Flickr
View fetch-by-tag.py
 import re import json import os from urllib.request import urlopen, urlretrieve from glob import glob config = { 'api_key': 'YOUR_API_KEY', 'sort': 'interestingness-desc', 'per_page': 100
Created Sep 8, 2011
Automatic post latest smiley on your timeline (Plurk API 1.0)
View plurk-smiley-notifier.py