Skip to content

Instantly share code, notes, and snippets.

View baiyanhuang's full-sized avatar

Baiyan Huang baiyanhuang

  • The Trade Desk
  • Shanghai
View GitHub Profile
@baiyanhuang
baiyanhuang / list_quick_sort.h
Created April 3, 2011 11:23
quick sort of single linked list
#pragma once
#include <utility>
//
// Quick sort for single linked list
//
// Template arguments:
// T: node's pointer type
// Next: function/functor to get next node
// Compare: functor to compare 2 arguments
//
@baiyanhuang
baiyanhuang / get_loc_in_ip_range.cc
Created April 4, 2011 00:07
(转)有一组从IP范围到地理位置信息的数据,不同地点的IP范围没有重叠,实现从单个IP地址查到相应的地理位置。
#include <iostream>
#include <algorithm>
#include <stdint.h>
#include <string>
#include <map>
#include <cassert>
using namespace std;
// ip range is expressed as [startIP, endIP)
@baiyanhuang
baiyanhuang / ProcessTerminator.cc
Created April 5, 2011 01:45
A program to terminate all processes of same name in Windows
#include <windows.h>
#include <Tlhelp32.h>
int _tmain(int argc, const TCHAR* argv[])
{
if(argc != 2) return -1;
TCHAR* processName = argv[1];
PROCESSENTRY32 ppe = {0};
@baiyanhuang
baiyanhuang / WindowsTimer
Created April 5, 2011 01:48
Simple timing function and class to profile program in Windows
LONGLONG GetFrequency()
{
LARGE_INTEGER qpFrequency;
::QueryPerformanceFrequency(&qpFrequency);
return qpFrequency.QuadPart;
}
double Tick()
{
static LONGLONG llFrequency = GetFrequency();
@baiyanhuang
baiyanhuang / ShellExecute
Created April 5, 2011 02:05
Execute a windows program like shell execute
int ExecuteCommand(const TCHAR* commandLine)
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
BOOL bRet;
DWORD lpExitCode;
memset(&si, 0, sizeof(si));
si.cb = sizeof(si);
@baiyanhuang
baiyanhuang / GetProcessName.cc
Created April 5, 2011 02:06
Get process handle by its name in Windows
HANDLE GetProcessByName(const TCHAR* szProcessName)
{
if(szProcessName == NULL) return NULL;
CString strProcessName = szProcessName;
DWORD aProcesses[1024], cbNeeded, cProcesses;
if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) )
return NULL;
// Calculate how many process identifiers were returned.
@baiyanhuang
baiyanhuang / .vimrc
Created April 6, 2011 13:57
My vim configuration file
if(has("win32") || has("win95") || has("win64") || has("win16")) "判定当前操作系统类型
let g:iswindows=1
else
let g:iswindows=0
endif
set nocompatible "不要vim模仿vi模式,建议设置,否则会有很多不兼容的问题
syntax on"打开高亮
if has("autocmd")
filetype plugin indent on "根据文件进行缩进
augroup vimrcEx
@baiyanhuang
baiyanhuang / merge_sort.c
Created April 28, 2011 12:48
数组版本的归并排序
#include <cstdio>
void merge(int* input, int* left, int nLeft, int* right, int nRight)
{
int i = 0;
// copy until one array ends
int l = 0, r = 0;
while(l < nLeft && r < nRight)
{
--Bubble Sort
-- 1, 3, 2, 7
function bubble_sort(arr)
for i=table.getn(arr), 2, -1 do -- each loop put one element in right position, decrease!
for j=2, i do -- inside the loop, do the exchange one by one
if arr[j] < arr[j-1] then
tmp = arr[j-1]
arr[j-1] = arr[j]
arr[j] = tmp
end
# sleep sort!!!
use strict;
use Thread;
my @threads;
my $count = 0;
foreach my $n (@ARGV) {