Skip to content

Instantly share code, notes, and snippets.

@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 / link_list_revert.c
Created April 25, 2012 07:41
单链表翻转
@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
*/
#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 / 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 {
@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 / .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