Skip to content

Instantly share code, notes, and snippets.

Baiyan Huang baiyanhuang

View GitHub Profile
View SpinLock
#pragma once
#include <atomic>
#include <algorithm>
#include "AlignAs.H"
/*
* 1. release-acquire memory order
* 2. false sharing and cache line
* 3. alignas
*
View look_and_say.py
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]
View bound_algo.cpp
// 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 Dec 8, 2012
Display address of program segments
View programsegment.cpp
#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 Dec 2, 2012
monitor a domain, send a mail if it is no longer "pendingDelete"
View monitorweb.pl
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 Nov 28, 2012
数组有N个元素,每个元素可能是红色、白色或蓝色。现在要把它们按照颜色排序(左红中白右蓝)。写出代码。
View sort-by-color.lua
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 Nov 23, 2012
Use lua to manipulate functions
View bar-premake-use.lua
LIBS = {}
DEPS = {}
EXPORTS = {'bar'}
bar = {}
function bar.use_nonpopular_bar()
print 'bar.use_nonpopular_bar'
end
@baiyanhuang
baiyanhuang / subgraph.dot
Created Nov 22, 2012
graphviz dot subgraph example
View subgraph.dot
digraph
{
subgraph cluster_solution
{
label="solution"
App;
foo;
baz;
}
App -> foo;
@baiyanhuang
baiyanhuang / producer-consumer-coroutine.lua
Created Nov 17, 2012
use coroutine to implement producer-consumer
View producer-consumer-coroutine.lua
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 Nov 11, 2012
Build lua with cmake
View CMakeLists.txt
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)
You can’t perform that action at this time.