Skip to content

Instantly share code, notes, and snippets.

@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)
@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)
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 / 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"
@wancw
wancw / git-branches-contain.sh
Last active August 29, 2015 14:04
Utils for merged branch
#!/bin/sh
export FMC_WRAPPER=`basename $0`
MERGE_COMMIT=`git find-merge-commit $*`
if [[ $? != 0 ]]; then
exit $?
fi
git branch --all --contain $MERGE_COMMIT
@wancw
wancw / y-combinator.go
Last active September 19, 2023 20:22
Y combinator in Go, runable example: http://play.golang.org/p/xVHw0zoaWX
package main
import "fmt"
type (
tF func(int) int
tRF func(tF) tF
tX func(tX) tF
)
@wancw
wancw / dl_and_gen_doc.bash
Last active November 21, 2019 07:45
Download WebRTC Java source code to generate Javadoc and Dash Docset
#!/usr/bin/env bash
WEBRTC_REPO=http://webrtc.googlecode.com/svn/trunk
WEBRTC_REV=7217
svn checkout ${WEBRTC_REPO}/talk/app/webrtc/java@r${WEBRTC_REV} peer_connection
svn checkout ${WEBRTC_REPO}/webrtc/modules/audio_device/android/java@r${WEBRTC_REV} audio_device
svn checkout ${WEBRTC_REPO}/webrtc/modules/video_capture/android/java@r${WEBRTC_REV} video_capture
svn checkout ${WEBRTC_REPO}/webrtc/modules/video_render/android/java@r${WEBRTC_REV} video_render
@wancw
wancw / friend class template method.cpp
Created October 21, 2014 08:33
Declare a method of class template as friend funciton
// Generic template
template <typename T>
struct Foo {
static int bar(const T& t) { return -1; }
};
// Specialization
class C;
template<>
@wancw
wancw / 01 accumulator generator.cpp
Last active August 29, 2015 14:08
C++ implementation of accumulator described in http://www.paulgraham.com/icad.html
template<typename T>
struct Accumulator {
Accumulator(T n) : n_{n} {}
template <typename U>
const T& operator()(const U& i) { return n_ += i; }
private:
T n_;
};
template <typename T>