Skip to content

Instantly share code, notes, and snippets.

View qi7chen's full-sized avatar
🎯
Focusing

Johnnie qi7chen

🎯
Focusing
  • Ubisoft
  • Chengdu
View GitHub Profile
@qi7chen
qi7chen / strtol.c
Last active November 7, 2015 07:05
string to long
/***
*strtol.c - Contains C runtimes strtol and strtoul
*
* Copyright (c) Microsoft Corporation. All rights reserved.
*
*Purpose:
* strtol - convert ascii string to long signed integer
* strtoul - convert ascii string to long unsigned integer
*
*******************************************************************************/
@qi7chen
qi7chen / __RTDynamicCast.cpp
Created November 21, 2011 08:51
part of dynamic_cast source
//only ptrdiff_t and size_t allowed
template <typename R>
R ReadData(size_t ptr)
{
return *((const R*)ptr);
}
template <typename R, typename T>
R ReadData(const T* ptr)
{
@qi7chen
qi7chen / rtti_struct.h
Created November 21, 2011 09:08
base rtti data structure
#include <typeinfo>
typedef std::type_info TypeDescriptor;
struct PMD
{
ptrdiff_t mdisp; // vftable offset
ptrdiff_t pdisp; // vbtable offset
@qi7chen
qi7chen / composed_functor.h
Created March 14, 2012 02:46
compose function adapter, f(g(x)), f(g(x, y)), f(g(x), h(x)), f(g(x), h(y))
/**
* @file: composed_functor.h
* @brief: compose function adapter, f(g(x)), f(g(x, y)), f(g(x), h(x)), f(g(x), h(y))
*
* @author: [email protected]
* @date: Dec 12, 2010
*/
#ifndef COMPOSE_FUNCTOR_H
#define COMPOSE_FUNCTOR_H
@qi7chen
qi7chen / showip.c
Created March 23, 2012 04:42
showip program, linux only
/*
** showip.c -- show IP addresses for a host given on the command line
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
@qi7chen
qi7chen / malloc.h
Created March 23, 2012 04:45
malloc by Doug Lea, header file
/*
Default header file for malloc-2.8.x, written by Doug Lea
and released to the public domain, as explained at
http://creativecommons.org/licenses/publicdomain.
last update: Wed May 27 14:25:17 2009 Doug Lea (dl at gee)
This header is for ANSI C/C++ only. You can set any of
the following #defines before including:
@qi7chen
qi7chen / malloc.c
Created March 23, 2012 04:46
malloc by Doug Lea, source file
/*
This is a version (aka dlmalloc) of malloc/free/realloc written by
Doug Lea and released to the public domain, as explained at
http://creativecommons.org/licenses/publicdomain. Send questions,
comments, complaints, performance data, etc to [email protected]
* Version 2.8.4 Wed May 27 09:56:23 2009 Doug Lea (dl at gee)
Note: There may be an updated version of this malloc obtainable at
ftp://gee.cs.oswego.edu/pub/misc/malloc.c
@qi7chen
qi7chen / run_length.py
Last active October 2, 2015 20:47
run length compress variant
#! /usr/bin/env python
from itertools import groupby
MAX_LEN = 8
OFFSET = 0xFF - MAX_LEN # 0xF7
XORCODE = 0x8f
@qi7chen
qi7chen / bigint.cpp
Created November 17, 2012 14:06
大数运算
//
//
// 乘法 http://en.wikipedia.org/wiki/Multiplication_algorithm
// 除法 http://en.wikipedia.org/wiki/Division_algorithm
//
// 参考实现:
// GNU GMP库 http://gmplib.org/manual/Algorithms.html#Algorithms
// BigInt库 http://mattmccutchen.net/bigint
@qi7chen
qi7chen / divide.c
Created December 9, 2012 03:50
divide algorithm use shift and substract
/*
These functions are examples of unsigned and signed integer division.
The algorithms assume 32-bit integers. The algorithms used are
from
Digital Computer Arithmetic, by Joseph J.F. Cavanaugh
McGraw Hill, 1984.