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 / recursive-descent.cc
Created August 19, 2016 14:43
Top Down Operator Precedence - Douglas Crockford's Javascript
#include <iostream>
#include <assert.h>
const char* code = "-1+2*3";
const char* token = nullptr;
void init() {
token = code;
}
@AndrewTsao
AndrewTsao / utf8bom.sh
Created May 20, 2016 05:21
使用BASH对文本文件进行编码格式转换格
has_bom()
{
head -c3 "$1" | grep -qP '\xef\xbb\xbf';
}
utf8bom()
{
echo "convert " $1
has_bom $1
if [ $? -ne 1 ]; then
@AndrewTsao
AndrewTsao / alignment.cc
Last active April 11, 2016 02:28
测试alignment对内存访问性能的影响
#include <iostream>
#include <stdint.h>
template<typename T>
inline void copy_byte(uint8_t* dst, uint8_t* src, size_t size ) {
T* sdst = (T*)dst;
T* ssrc = (T*)src;
size /= sizeof(T);
clock_t s = clock();
while (size-- > 0)
@AndrewTsao
AndrewTsao / vector_iteration.cc
Last active January 27, 2016 13:52
STL Vector
#include <iostream>
#include <iomanip>
#include <time.h>
#include <vector>
struct Item {
int a;
Item(int i): a(i) {
std::cout << "ctor" << std::endl;
@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)的方式进行。
在这种分配方法下,给定记录编号,算出记录所属的内存块及其在内存块中的偏移。
*/
@AndrewTsao
AndrewTsao / STEP.md
Created December 13, 2015 14:31
上交所深交所原始数据消息类型列表

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

消息类型码 含义
UA1115 A+H市场状态
UA1202 3 心跳消息(Heartbeat)
UA2102 A+H个股行情
UA2107 A+H个股集合竞价
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 / 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);
}
@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 / 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