Skip to content

Instantly share code, notes, and snippets.


Grey Lee bcse

View GitHub Profile
from math import fmod, modf, sqrt, degrees, radians, sin, cos, atan2
# Mean Earth radius defined by IUGG. (Unit: meters)
# ref.
EARTH_RADIUS = 6371009.
def distance((lat1, lng1), (lat2, lng2)):
"""Get approximate geographical distance between 2 coordinates in meters.
bcse / README.markdown
Last active Oct 7, 2015
Python SortedList
View README.markdown

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:


Test with 10000 random numbers...
Raw list takes 1.01116704941 seconds
Raw list, sort once takes 0.00338888168335 seconds
bcse /
Created Apr 10, 2012
Recursively list files
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__':
bcse / scrdec18-VC8.exe
Created Feb 15, 2012
Windows Script Decoder 1.8 (Decoding JScript.Encoded)
registry = {}
class MultiMethod(object):
def __init__(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:
bcse /
Last active Sep 27, 2015
Fetch top 100 popular photos from Flickr
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
bcse /
Created Sep 8, 2011
Automatic post latest smiley on your timeline (Plurk API 1.0)
#!/usr/bin/env python
#--- Setup ---------------------------------------------------
import sys, os, urllib, urllib2, cookielib
import json
bcse / dbbackup.php
Created Sep 8, 2011
Backup all MySQL databases and send to my E-mail
View dbbackup.php
$boundary = '==DBBACKUP-'.md5(uniqid(rand(), true));
$date = date('Ymd');
$header = "Content-Type: multipart/mixed; boundary=\"$boundary\"";
$message =
"This is a multi-part message in MIME format.\n".
bcse /
Created Aug 22, 2011
Compile FFmpeg/Libav for iOS
# configure for armv7 build
./configure \
--cc=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc \
--as='/usr/local/bin/ /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc' \
--sysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk \
--target-os=darwin \
--arch=arm \
--cpu=cortex-a8 \
--extra-cflags='-arch armv7' \
--extra-ldflags='-arch armv7 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk' \
bcse /
Created Mar 8, 2011
Convert black to opaque and white to transparent. (Depends on pypng)
import png
def convert(fin, fout):
reader = png.Reader(filename=fin)
width, height, pixels, metadata = reader.asDirect()
#print metadata
out = list()
for row in pixels:
row_out = list()
You can’t perform that action at this time.