Skip to content

Instantly share code, notes, and snippets.

View falcondai's full-sized avatar

Falcon Dai falcondai

View GitHub Profile
@falcondai
falcondai / mp3_tag.py
Created May 2, 2012 17:36
This module provides MP3 tags conversion from any (python-supported) encoding to UTF-8.
# File: mp3_tag.py
#
# Description: This module provides MP3 tags correction, i.e. from
# any encoding X to UTF-8, the standard across different apps
# and platforms. The default parameters target the common Chinese
# encoding GBK.
#
# Features: 1. it recursively handles MP3 files > 512KB in all subdirectories.
# 2. outputs a log formatted to show the directory structure
# with failures (decoding/encoding error, the field will be
@falcondai
falcondai / benchmark.py
Created May 2, 2012 17:58
This computes the average run time of a piece of python code.
# File: benchmark.py
# Desc: This computes the average run time of a piece of code.
# Author: Falcon Dai
# Date: 5/2/2012
import time
global_dict = globals()
# should be run as soon as the module is imported to
@falcondai
falcondai / donation_gadget.html
Created July 10, 2012 08:22
A gadget that combines Google Wallet/Checkout and PayPal's donation buttons at one place. It also provides input validation and Google analytics integration. Disclaimer: you can use this freely but it does not have any warranty.
<!-- Google Checkout/Paypal donation gadget -->
<!-- written by Falcon Dai, falcondai.com -->
<!--
Usage: Replace all occurrences of {mid} by your Google Merchant ID, {name} by your name, and {pid} by your PayPal account email then it should work.
Disclaimer: you can use this freely but it does not have any warranty. If you like it, you can buy me a coffee.
-->
<p>You can buy me a coffee!</p>
<b>via Google Checkout</b>
@falcondai
falcondai / d3-cache-helper.js
Created September 21, 2012 18:51
Use Web Storage (or fallback to a JS object) to cache jsons for the async JSON method in d3js (http://d3js.org/).
// use HTML5 Web Storage or an object to cache
localStorage = localStorage || sessionStorage || {};
sessionStorage = sessionStorage || {};
// @param work: a function that works on k, i.e. of the form function(k) {}
// @param is_permanent: true if the data should be stored in localStorage, else in sessionStorage
function perform(work, k, url, is_permanent) {
var s = is_permanent? localStorage : sessionStorage;
if (s[k]) {
@falcondai
falcondai / barchart.html
Last active December 19, 2015 21:48
a reusable bar chart (following the paradigm lay out in mbostock's blog post: http://bost.ocks.org/mike/chart/).
<!doctype html>
<style>
body {
font: 10px sans-serif;
}
.axis path,
.axis line {
fill: none;
@falcondai
falcondai / .emacs
Last active December 21, 2015 00:18
custom init setup for Emacs 24
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(custom-enabled-themes (quote (deeper-blue)))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
@falcondai
falcondai / Makefile
Last active December 21, 2015 03:58
Makefile for packaging chrome extensions
EXT_NAME=omni
all: clean pages package
pages:
jade jade/*.jade -Po .
clean:
rm -rf *~
rm -f $(EXT_NAME).zip
@falcondai
falcondai / install-fonts.sh
Last active February 5, 2016 19:36
install all fonts files under a directory recursively (for Ubuntu).
#!/bin/bash
echo installing fonts at $PWD to ~/.fonts/
find . -name '*.ttf' -exec cp \{\} ~/.fonts/ \;
find . -name '*.otf' -exec cp \{\} ~/.fonts/ \;
echo finished installing
@falcondai
falcondai / JavaDoc.tmLanguage
Created August 20, 2013 16:00
Fix to Sublime Text 2's JavaDoc parsing
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>fileTypes</key>
<array/>
<key>foldingStartMarker</key>
<string>/\*\*</string>
<key>foldingStopMarker</key>
<string>\*\*/</string>
@falcondai
falcondai / lazy_csv_reader.py
Created December 20, 2013 15:33
lazy wrapper for CSV reader in Python
class lazy_csv_reader(list):
def __init__(self, csv_reader, pos):
self.reader = csv_reader
self.pos = pos
def __iter__(self):
r = self.reader.next()
while r:
yield r[self.pos]
r = self.reader.next()