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 / 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 / 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 / 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 / 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;
}