Skip to content

Instantly share code, notes, and snippets.

Grey Lee bcse

Block or report user

Report or block bcse

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
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.
@bcse
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:

bisectlist.SortedList

Test with 10000 random numbers...
Raw list takes 1.01116704941 seconds
Raw list, sort once takes 0.00338888168335 seconds
@bcse
bcse / locate.py
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__':
@bcse
bcse / scrdec18-VC8.exe
Created Feb 15, 2012
Windows Script Decoder 1.8 (Decoding JScript.Encoded)
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:
@bcse
bcse / fetch-by-tag.py
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
@bcse
bcse / plurk-smiley-notifier.py
Created Sep 8, 2011
Automatic post latest smiley on your timeline (Plurk API 1.0)
View plurk-smiley-notifier.py
#!/usr/bin/env python
APIKEY = 'YOUR_APIKEY'
USERNAME = 'YOUR_USERNAME'
PASSWORD = 'YOUR_PASSWORD'
#--- Setup ---------------------------------------------------
import sys, os, urllib, urllib2, cookielib
try:
import json
except:
@bcse
bcse / dbbackup.php
Created Sep 8, 2011
Backup all MySQL databases and send to my E-mail
View dbbackup.php
<?php
$DBUSERNAME = 'YOUR_USERNAME';
$DBPASSWORD = 'YOUR_PASSWORD';
$EMAIL = 'YOUR_EMAIL';
$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
bcse / build-ffmpeg.sh
Created Aug 22, 2011
Compile FFmpeg/Libav for iOS
View build-ffmpeg.sh
# configure for armv7 build
./configure \
--cc=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc \
--as='/usr/local/bin/gas-preprocessor.pl /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
bcse / greyscale2alpha.py
Created Mar 8, 2011
Convert black to opaque and white to transparent. (Depends on pypng)
View greyscale2alpha.py
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.