Skip to content

Instantly share code, notes, and snippets.

@stephenLee
stephenLee / virtual.md
Created December 5, 2012 15:44
virtualenvwrapper usages
  • source /usr/local/bin/virtualenvwrapper.sh
    
  • mkvirtualenv env1
    
  • ls $WORKON_HOME
    
  • lssitepackages
    
  • Switch environments with workon workon env2
  • deactive
    
  • rmvirtualenv env2
    
@stephenLee
stephenLee / tools.md
Created November 16, 2012 13:30
tools to explore object/executable files
  • ar

creates static libraries.

  • ldd

lists the shared libraries on which the object binary is dependent.

  • nm

lists the symbols defined in the symbol table of an object file.

  • objdump
@stephenLee
stephenLee / functors.cc
Created November 16, 2012 13:28
Functors(Function objects) demo
// A functor is any object that can be used with () in the manner of a function.
// includes pointers to functions, and class objects for which the () operator (function call operator) is overloaded
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
@stephenLee
stephenLee / smart_pointer.cc
Created November 16, 2012 12:46
auto_ptr demo
// avoid resource leaks when exceptions are thrown.
// if an exception occurs after successful memory allocation but
// before the delete statement executes, a memory leak could occur.
// void memory_leak()
//{
// ClassA * ptr = new ClassA;
// try {
// ...
// }
// catch(...) {
@stephenLee
stephenLee / bitwise-operators.md
Created November 12, 2012 11:41 — forked from dideler/bitwise-operators.md
Bitwise tricks

Inspired by this article. Neat tricks for speeding up integer computations.

Note: cin.sync_with_stdio(false); disables synchronous IO and gives you a performance boost. If used, you should only use cin for reading input (don't use both cin and scanf when sync is disabled, for example) or you will get unexpected results.

Multiply by a power of 2

x = x << 1; // x = x * 2

@stephenLee
stephenLee / maze.py
Created November 10, 2012 13:08
迷宫问题求解
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import Queue
"""
Problem:(from http://weibo.com/lirenchen)
从图左边入口处的2011进去,在迷宫里转悠,最后变成2012从右边出来。可以在迷宫里转圈,
@stephenLee
stephenLee / bithack.cc
Created November 6, 2012 13:56
bit manipulation tricks(collections)
/*
* Reference:
* http://www.quora.com/Computer-Programming/What-are-some-cool-bit-manipulation-tricks-hacks
* http://www.catonmat.net/blog/low-level-bit-hacks-you-absolutely-must-know/
*/
#include <iostream>
#include <string.h>
using namespace std;
@stephenLee
stephenLee / Makefile
Created October 23, 2012 16:27
Tiny Makefile template for c++
# define variable, use using $()
# -g add debug information to the executable file
# -Wall turns on most, but not all, compiler warnings
# using Emacs and M-x replace-string RET string RET newstring RET
# to replace xx to your file name.
# Use google's testing framework
GTEST_DIR = ../gtest
# Where to find user code.
USER_DIR = ../gtest_sample
@stephenLee
stephenLee / Makefile
Created October 23, 2012 16:27
Tiny Makefile template for c/c++
# define variable, use using $()
# -g add debug information to the executable file
# -Wall turns on most, but not all, compiler warnings
CC = g++
CFLAGS = -g -Wall
file: file.o
$(CC) $(CFLAGS) -o file file.o
file.o: file.cpp
@stephenLee
stephenLee / weibo_nooauth.py
Created October 23, 2012 00:03
weibo_login script
#!/usr/bin/env python
#coding=utf8
import urllib
import urllib2
import cookielib
import base64
import re
import json
import hashlib
import os