Skip to content

Instantly share code, notes, and snippets.

View AndrewTsao's full-sized avatar
🎯
Focusing

andi AndrewTsao

🎯
Focusing
  • SHANGHAI, Boshen,CN
  • PUDONG, SHANGHAI, CN
View GitHub Profile
@AndrewTsao
AndrewTsao / buildit.bat
Created July 20, 2012 15:06 — forked from adam-singer/buildit.bat
Building dart on win32, the quick guide
cd c:\
mkdir dart_bleeding
svn co http://gyp.googlecode.com/svn/trunk build/gyp
mkdir dart-repo
set Path=%PATH%;c:\dart_bleeding\build\gyp\
git svn clone -rHEAD "https://dart.googlecode.com/svn/branches/bleeding_edge/dart" dart
gclient config "https://dart.googlecode.com/svn/branches/bleeding_edge/deps/all.deps"
cd dart
gclient sync
gclient runhooks
@AndrewTsao
AndrewTsao / Makefile
Created December 9, 2012 01:56
测试Lua table中以lightuserdata和string作key的性能
all:
gcc -O2 -fpic -c -o symbol.o symbol.c
gcc -O -shared -fpic -o symbol.so symbol.o
@AndrewTsao
AndrewTsao / hello2013.cc
Created December 31, 2012 13:25
Learn CompoundExpression in supersonic.
static void LearnCompoundExpression() {
scoped_ptr<CompoundExpression> tuple(new CompoundExpression());
tuple->AddAs("from", ConstString("Supersonic: "));
tuple->AddAs("say",
If(Less(ConstInt32(28), ConstInt32(29)),
ConstString("Hello"),
ConstString("World")));
tuple->AddAs("comma", ConstString(","));
tuple->AddAs("new", Plus(ConstInt32(2012), ConstInt32(1)));
scoped_ptr<Operation> compute(Compute(tuple.release(), Generate(10)));
@AndrewTsao
AndrewTsao / lua_mem_usage.c
Created January 1, 2013 07:45
Measuring lua vm memory usage
#include <stdio.h>
#include <stdlib.h>
#include "lua5.1/lua.h"
#include "lua5.1/lauxlib.h"
#include "lua5.1/lualib.h"
// Measuring lua vm memory usage.
// build: gcc main.c -llua5.1 -lm -ldl -fPIC
static size_t mem_used = 0;
@AndrewTsao
AndrewTsao / repl.lua
Created March 24, 2013 05:13
repl.lua
function repl()
local cmd, res, msg1, msg2
-- R
io.write '>'
cmd = io.read()
if not cmd or #cmd == 0 then
return repl()
end
res, msg1 = loadstring(cmd, 'repl')
if not res then
@AndrewTsao
AndrewTsao / p2.lua
Created April 27, 2014 13:55
learning lpeg module to write a mini expression executor.
--
-- Created by IntelliJ IDEA.
-- User: andi
-- Date: 14-4-27
-- Time: 下午7:07
-- To change this template use File | Settings | File Templates.
--
local sqrt = require("math").sqrt
local re = require("re")
@AndrewTsao
AndrewTsao / container_of.h
Created May 17, 2015 14:35
CONTAINER_OF for C++
template <class T, typename M>
T* container_of(M *m, const M T::*mp) {
static const T * null = reinterpret_cast<const T *>(null);
static const ptrdiff_t offset = reinterpret_cast<const ptrdiff_t>(&(null->*mp));
return reinterpret_cast<T*>(reinterpret_cast<char*>(m) - offset);
}
cmake_minimum_required (VERSION 2.8)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
project (QuantBox_XAPI)
set(CMAKE_CXX_FLAGS "-std=c++11")
include_directories(.)
include_directories(QuantBox_Queue)
#add_subdirectory(./)
set(QUEUE_SRC_LIST
QuantBox_Queue/readerwriterqueue.h
@AndrewTsao
AndrewTsao / STEP.md
Created December 13, 2015 14:31
上交所深交所原始数据消息类型列表

上交所行情消息编号及意义

消息类型码 含义
UA1115 A+H市场状态
UA1202 3 心跳消息(Heartbeat)
UA2102 A+H个股行情
UA2107 A+H个股集合竞价
@AndrewTsao
AndrewTsao / CalculatePositionByIndex.cc
Created January 9, 2016 17:20
一个如下的内存分配方法,初始分配2^n条记录,然后按倍增的方式。 当达到2^(n+m)时,改为每次分配2^(n+m)的方式进行。 在这种分配方法下,给定记录编号,算出记录所属的内存块及其在内存块中的偏移。
#include <iostream>
#include <iomanip>
/*
一个如下的内存分配方法,初始分配2^n条记录,然后按倍增的方式。
当达到2^(n+m)时,改为每次分配2^(n+m)的方式进行。
在这种分配方法下,给定记录编号,算出记录所属的内存块及其在内存块中的偏移。
*/