Skip to content

Instantly share code, notes, and snippets.

@wancw
wancw / timereport.plugin.zsh
Last active August 29, 2015 14:02
Report elapsed time for command take long time to execute.
typeset -gaU preexec_functions
typeset -gaU precmd_functions
preexec_functions+='preexec_start_timer'
precmd_functions+='precmd_report_time'
_tr_current_cmd="?"
_tr_sec_begin="${SECONDS}"
_tr_ignored="yes"
import urllib, urllib2, json
'''
The ``FacebookTestUserManager`` module
======================================
Author: Weizhong Yang <zonble at gmail dot com>
A tool which helps to create and delete test account for Facebook.
@wancw
wancw / git-today-summary
Created December 19, 2013 10:32
Summarize what you did today.
#!/usr/bin/env bash
git log --all --since=midnight --author="$USER" $* --format='%d' --numstat \
| awk -f <(cat <<- 'SCRIPT'
/\(/ { NB=NB+1 ; next }
NF==3 { ADD=ADD+$1; DEL=DEL+$2; NC=NC+1 }
END { printf "+%d, -%d in %d commit(s), %d branch(es)\n", ADD, DEL, NC, NB }
SCRIPT)
@wancw
wancw / ls-migrations-then-checkout
Last active December 16, 2016 18:55
列出切換 branch 前需要 rollback 的 South migration。
#!/usr/bin/env zsh
if [[ $# != 1 ]]; then
cat - << USAGE
Usage: `basename $0` <branch>
USAGE
return 1
fi
local old_branch=$(git rev-parse --abbrev-ref HEAD)
import android.view.View;
import android.view.ViewGroup;
/**
* A {@link ViewGroup.OnHierarchyChangeListener hierarchy change listener} which recursively
* monitors an entire tree of views.
*/
public final class HierarchyTreeChangeListener implements ViewGroup.OnHierarchyChangeListener {
/**
* Wrap a regular {@link ViewGroup.OnHierarchyChangeListener hierarchy change listener} with one
@wancw
wancw / pr.md
Created March 28, 2013 02:11 — forked from piscisaureus/pr.md

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

#include <stdio.h>
typedef void (*func_ptr_t)(int x, ...);
void foo(int x) {
printf("foo(%d)\n", x);
}
void bar(int x, int y, int z) {
printf("foo(%d, %d, %d)\n", x, y, z);
@wancw
wancw / LICENSE.txt
Created August 15, 2012 05:57 — forked from jed/LICENSE.txt
generate random UUIDs
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Jed Schmidt <http://jed.is>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@wancw
wancw / radix_sleep_sort.rb
Created June 24, 2011 09:17
Mix of radix sort and sleep sort. (inspired by @fcamel)
#!/usr/bin/env ruby
#
# fcamel's implementation in Python: https://gist.github.com/1042867
#
def radix_sleep_sort(numbers)
max_length = numbers.map {|n| n.to_s.length }.max
return numbers if max_length.nil?