Skip to content

Instantly share code, notes, and snippets.

@zhpengg
zhpengg / .vimrc
Created December 12, 2011 01:58
vimrc start
set nocompatible
syntax enable
set encoding=utf-8
set showcmd " display incomplete commands
"" Whitespace
set nowrap " don't wrap lines
set tabstop=2 shiftwidth=2 " a tab is two spaces
set expandtab " use spaces, not tabs
set backspace=indent,eol,start " backspace through everything in insert mode
@zhpengg
zhpengg / bsearch.cpp
Created December 13, 2011 09:55
binary search in cpp
#include <iostream>
#include <vector>
using namespace std;
template <typename t>
typename vector<t>::iterator mbsearch(vector<t> &haystack, t key)
{
typename vector<t>::iterator left, middle, right;
left = haystack.begin();
@zhpengg
zhpengg / dyndns.php
Created February 6, 2012 09:33
dyndns.php
<?php
$domain_list = array('deer', 'hippo', 'lion');
$domain = empty($_GET['domain']) ? '' : $_GET['domain'];
$address = empty($_GET['address']) ? '' : $_GET['address'];
if ($domain && $address && in_array($domain, $domain_list)) {
file_put_contents($domain.'.txt', $address);
echo 'OK';
} else {
#include <sys/time.h> // for gettimeofday()
class StopWatch {
timeval started;
std::string msg;
public:
StopWatch(const std::string& m): msg(m)
{ gettimeofday(&started, NULL); }
@zhpengg
zhpengg / reverse.c
Created April 24, 2012 09:01
reverse a string separated by ';'
#include <stdlib.h>
#include <stdio.h>
/**
* @file reverse.c
* @brief 反转按照‘;’分割的字符串
* @author zhpeng.is@gmail.com
* @version 0.0.1
* @date 2012-04-24
*/
@zhpengg
zhpengg / link_list_revert.c
Created April 25, 2012 07:41
单链表翻转
@zhpengg
zhpengg / 32bit-multiply.cc
Created April 26, 2012 11:36
32为整数保存32位乘法结果
#include <cstdio>
#include <cstdlib>
#include <stdint.h>
struct UInt64 {
uint32_t high;
uint32_t low;
};
UInt64 multiply(uint32_t a, uint32_t b)
@zhpengg
zhpengg / get_random64.c
Created April 28, 2012 03:30
使用/dec/random获取64bit随机数
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdint.h>
#include <inttypes.h>
int main()
{
@zhpengg
zhpengg / lru_cache.c
Created May 23, 2012 07:25 — forked from jehiah/lru_cache.c
a LRU cache in C using uthash
#include <string.h>
#include <uthash.h>
// this is an example of how to do a LRU cache in C using uthash
// http://uthash.sourceforge.net/
// by Jehiah Czebotar 2011 - jehiah@gmail.com
// this code is in the public domain http://unlicense.org/
#define MAX_CACHE_SIZE 100000
@zhpengg
zhpengg / lru.cc
Created May 23, 2012 15:39
LRU Cache Demo In C++
#include <iostream>
#include <string>
#include <map>
using namespace std;
struct entry {
entry(string k, int v, entry *n, entry *p):
key(k), value(v), next(n), prev(p){}
string key;
int value;