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
#pragma once
#include <atomic>
#include <algorithm>
#include "AlignAs.H"
/*
* 1. release-acquire memory order
* 2. false sharing and cache line
* 3. alignas
*
def look_and_say(member):
while True:
num = []
count = []
pre = None
for ele in member:
if len(num) > 0 and pre == ele:
count[len(count)-1] += 1
else:
num += [ele]
// 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 / 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 / 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;
@baiyanhuang
baiyanhuang / producer-consumer-coroutine.lua
Created November 17, 2012 13:25
use coroutine to implement producer-consumer
function consumer(prod)
while true do
local x = receive(prod)
print(x)
end
end
function receive(prod)
local status, value = coroutine.resume(prod)
return value
@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)