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 / CMakeLists.txt
Created November 11, 2012 07:49
Build lua with cmake
cmake_minimum_required (VERSION 2.6)
project (lua) # project here actually means solution in premake
if(WIN32)
add_definitions( -D_CRT_SECURE_NO_WARNINGS )
endif()
# 1. lua static library
# how to rename library name?
add_library (lualib STATIC lapi.c lcode.c lctype.c ldebug.c ldo.c ldump.c lfunc.c lgc.c llex.c lmem.c lobject.c lopcodes.c lparser.c lstate.c lstring.c ltable.c ltm.c lundump.c lvm.c lzio.c lauxlib.c lbaselib.c lbitlib.c lcorolib.c ldblib.c liolib.c lmathlib.c loslib.c lstrlib.c ltablib.c loadlib.c linit.c)
@baiyanhuang
baiyanhuang / monitorweb.pl
Created December 2, 2012 01:15
monitor a domain, send a mail if it is no longer "pendingDelete"
use strict;
my $targetPage = $ARGV[0]; #http://www.kingtoo.com/reg/whois.asp?domain=douban.com
print $targetPage . "\n";
my @page = `curl $targetPage | iconv -f gb2312 -t utf8`;
chomp @page;
my $domainStatus;
for my $line (@page)
{
@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.
#pragma once
#include <atomic>
#include <algorithm>
#include "AlignAs.H"
/*
* 1. release-acquire memory order
* 2. false sharing and cache line
* 3. alignas
*
@baiyanhuang
baiyanhuang / disassem.c
Created June 10, 2012 07:15
A dissection of a simple c program's assembly
int main() {
00B61400 push ebp
00B61401 mov ebp,esp
00B61403 sub esp,0C0h // esp指向栈顶
00B61409 push ebx
00B6140A push esi
00B6140B push edi
00B6140C lea edi,[ebp-0C0h]
00B61412 mov ecx,30h //C0h 除以4,就是30h,因为rep stos用的是dword
00B61417 mov eax,0CCCCCCCCh //设置返回值为默认值:无效
// StlAlgo.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <vector>
#include <array>
#include <algorithm>
#include <iterator> // ostream_iterator
#include <iostream>
@baiyanhuang
baiyanhuang / programsegment.cpp
Created December 8, 2012 12:40
Display address of program segments
#include <iostream>
using namespace std;
// .data - read-write data
int rwdata = 100;
// .rodata - read-only data
const char* rodata = "hello, world";
@baiyanhuang
baiyanhuang / sort-by-color.lua
Created November 28, 2012 13:27
数组有N个元素,每个元素可能是红色、白色或蓝色。现在要把它们按照颜色排序(左红中白右蓝)。写出代码。
function printa(arr)
for _, v in ipairs(arr) do
io.write(v .. " ")
end
io.write("\n")
end
-- use consecutive number to represent the colors, like:
-- red: 1
@baiyanhuang
baiyanhuang / bar-premake-use.lua
Created November 23, 2012 01:48
Use lua to manipulate functions
LIBS = {}
DEPS = {}
EXPORTS = {'bar'}
bar = {}
function bar.use_nonpopular_bar()
print 'bar.use_nonpopular_bar'
end
@baiyanhuang
baiyanhuang / subgraph.dot
Created November 22, 2012 06:37
graphviz dot subgraph example
digraph
{
subgraph cluster_solution
{
label="solution"
App;
foo;
baz;
}
App -> foo;