Skip to content

Instantly share code, notes, and snippets.

View falcondai's full-sized avatar

Falcon Dai falcondai

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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