Skip to content

Instantly share code, notes, and snippets.

View baiyanhuang's full-sized avatar

Baiyan Huang baiyanhuang

  • The Trade Desk
  • Shanghai
View GitHub Profile
@baiyanhuang
baiyanhuang / result-g++.txt
Created July 16, 2012 02:22
Test the vptr position in object model
sizeof(Base)=16
sizeof(Derived)=16
0x7fffd1303400
0x7fffd1303408
vptr is at the beginning? true
@baiyanhuang
baiyanhuang / HashCodeGenerator .java
Created July 11, 2012 06:32
generate hashcode based on effective java
package baiyanhuang;
import java.util.Arrays;
/**
*
* A utility class to help generate hash code: This is based on the theory from Effective Java, Item 9
*
*/
public class HashCodeGenerator {
@baiyanhuang
baiyanhuang / constructor_seq.cpp
Created July 10, 2012 12:42
test the object construction sequence
#include <iostream>
using namespace std;
class Base
{
public:
Base() {cout << "Base constructor called" << endl;}
};
@baiyanhuang
baiyanhuang / singleton.cpp
Created July 1, 2012 09:31
Spin lock implementation in Windows and depends on it a double-checked singleton.
// we use double-lock check in singleton to solve the problem we met in spinlock1.cpp, but hey, that itself is a lock, it has to use some atomic intrusion/memory barrier to solve this synchronization problem
template<class T>
class SingletonHolder
{
private:
static volatile T* instance;
static volatile int m_lockObj;
SingletonHolder() {}
@baiyanhuang
baiyanhuang / mutex-test.cpp
Created July 1, 2012 08:35
spin lock with 9 threads waiting - who is next is random/mutex with 9 threads waiting, the first one in the queue will be the next
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include<iostream>
using namespace std;
static pthread_mutex_t foo_mutex;
void* get_maokeng(void* param)
{
@baiyanhuang
baiyanhuang / d3testing.html
Created June 29, 2012 02:13
test d3 framework.
<html>
<!-- http://d3js.org/ -->
<head>
<title> D3 Testing </title>
<script src="http://d3js.org/d3.v2.js"></script>
<style type="text/css">
body {
background-color: green;
color: white;
}
@baiyanhuang
baiyanhuang / array_size.h
Created June 17, 2012 03:13
A macro to get array size
#ifndef _LZ_UTILITY_COMMON_H
#define _LZ_UTILITY_COMMON_H
// Array size
template <typename T, size_t N>
char ( &_ArraySizeHelper( T (&array)[N] ) ) [N];
#define ARRAY_SIZE(array) ( sizeof( _ArraySizeHelper(array) ) )
#endif
@baiyanhuang
baiyanhuang / CleanSource.bat
Created June 17, 2012 02:24
remove all binary files in source folder
echo Clear Mir Baiyan's coding arena!!!
cd ..
del /f /s /q *.obj
del /f /s /q *.pdb
del /f /s /q *.ilk
del /f /s /q *.pch
del /f /s /q *.ib_tag
del /f /s /q *.idb
del /f /s /q *.exe
del /f /s /q *.ncb
@baiyanhuang
baiyanhuang / linked_list.cpp
Created June 17, 2012 02:17
#algorithm# quick sort by linked list
#include "linked_list.h"
#include "timer.h"
#include "LazyTest.h"
#include <list>
// standard
#include <ctime>
#include <random>
#include <algorithm>
#pragma once
#include <Windows.h>
#include <iostream>
// How to use:
// Example 1:
// double d1 = Tick();
// double d2 = Tick();
// double time = d2 - d1;
//