Skip to content

Instantly share code, notes, and snippets.

@wancw
wancw / 01_iterator_helper.hpp
Created December 19, 2014 22:40
Use iterator pointer in range-based for loop. Or you may just use boost::indirect_iterator - http://www.boost.org/doc/libs/1_57_0/libs/iterator/doc/indirect_iterator.html
#ifndef __01_ITERATOR_HELPER_H__
#define __01_ITERATOR_HELPER_H__
#include <memory>
/* We need a concreate iterator class */
template<typename It, typename Vt = typename It::valuetype>
class IteratorPointerWrapper {
public:
IteratorPointerWrapper(It* iter_ptr) : iter_ptr_(iter_ptr) {}
@wancw
wancw / recursive_rename.sh
Created December 19, 2014 10:41
Run rename(1) recursively
#!/bin/sh
TARGET_DIR="$1"
shift
FROM="$1"
shift
TO="$1"
shift
@wancw
wancw / abs_iter.cpp
Created December 19, 2014 07:41
C++ iterator abstraction
#include <vector>
#include <set>
#include <string>
namespace Impl {
typedef std::set<std::string> elem_container;
//typedef std::vector<std::string> elem_container;
typedef elem_container::iterator elem_iterator;
@wancw
wancw / .gitmodules
Last active August 29, 2015 14:11 — forked from littleq0903/.gitmodules
[submodule "zsh-syntax-highlighting"]
path = zsh-syntax-highlighting
url = git://github.com/zsh-users/zsh-syntax-highlighting.git

Keybase proof

I hereby claim:

  • I am wancw on github.
  • I am wancw (https://keybase.io/wancw) on keybase.
  • I have a public key whose fingerprint is 9272 9A56 09C5 C44E 8AA0 7B15 D8CF FF69 08A8 E5FF

To claim this, I am signing this object:

@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>
@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 / 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 / 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 / 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