Skip to content

Instantly share code, notes, and snippets.

View guohai's full-sized avatar
🎱
Hey

Brent G guohai

🎱
Hey
View GitHub Profile
#include <stdio.h>
#include <stdlib.h>
struct SBinaryTreeNode // a node of the binary tree
{
int m_nValue; // value of node
struct SBinaryTreeNode *m_pLeft; // left child of node
struct SBinaryTreeNode *m_pRight; // right child of node
};
@guohai
guohai / bitmap_gen_test.c
Created June 24, 2013 06:29
sample code for generate a bitmap image at x86_64 GNU/Linux
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// for Linux platform, plz make sure the size of data type is correct for BMP spec.
// if you use this on Windows or other platforms, plz pay attention to this.
typedef int LONG;
typedef unsigned char BYTE;
typedef unsigned int DWORD;
typedef unsigned short WORD;
@guohai
guohai / rund
Created February 27, 2013 14:11
launcher script for Dalvik on X86 Linux
#!/bin/sh
# base directory, at top of source tree; replace with absolute path
base=`pwd`
# configure root dir of interesting stuff
root=$base/out/host/linux-x86
export ANDROID_ROOT=$root
# configure bootclasspath
#define DECLARE_ENUM(E) struct E { public: E(int value = 0) : _value((__Enum)value) { } E& operator=(int value) { this->_value = (__Enum)value; return *this; } operator int() const { return this->_value; } enum __Enum {
#define END_ENUM() }; private: __Enum _value; };
#include <iostream>
using namespace std;
class B {
B &operator=(const B &);
};
@guohai
guohai / ArcTranslateAnimation.java
Created April 3, 2012 16:55
Curved Path Animation in Android
import android.graphics.PointF;
import android.view.animation.Animation;
import android.view.animation.Transformation;
// http://www.math.ubc.ca/~cass/gfx/bezier.html
public class ArcTranslateAnimation extends Animation {
private int mFromXType = ABSOLUTE;
private int mToXType = ABSOLUTE;
@guohai
guohai / AutoIncrementDemo.class
Created September 1, 2011 09:43
Java AutoIncrement Atomic Bytecode
// javap -c -l AutoIncrementDemo
Compiled from "AutoIncrementDemo.java"
public class AutoIncrementDemo extends java.lang.Object{
public AutoIncrementDemo();
Code:
0: aload_0
1: invokespecial #1; //Method java/lang/Object."<init>":()V
4: return
@guohai
guohai / ArrayPartition.java
Created August 29, 2011 04:05
array partition quicksort
/**
* 将数组分三块,中间一块是pivot[就一个元素],左边一块是所有元素都小于pivot,右边一块是所有元素都大于pivot<br />
* 快速排序的基础,简单易懂,居家旅行面试必备
*/
public class ArrayPartition {
public static void main(String[] args) {
int[] arr = { 4, 5, 3, 22, 1, 3 };
printArray(arr, "init");
System.out.println("pivot idx " + sort(arr, 0, arr.length - 1));
printArray(arr, "result");
@guohai
guohai / ThreadWaitSleepDemo.java
Created August 24, 2011 07:25
Thread sleep wait notify notifyAll
public class ThreadWaitSleepDemo {
public static void main(String[] args) {
// wait,notify,notifyAll三个方法都有共同点
// The current thread must own this object's monitor.
ThreadWaitSleepDemo obj = new ThreadWaitSleepDemo();
new S(obj).start();
try {
@guohai
guohai / MultipleThreadCalSum.java
Created August 17, 2011 14:31
一个非常非常大的int类型数组,用多线程计算和。假设数组长度M线程数量N
import java.util.concurrent.CountDownLatch;
import org.apache.commons.lang.math.RandomUtils;
public class MultipleThreadCalSum {
public static void main(String[] args) {
final int M = 10000000; // 10万个元素
final int N = 100; // 100个线程
@guohai
guohai / MailAttachmentFilenameDemo.java
Created August 11, 2011 13:47
为修复BUG快速写的一个读取邮件(eml)文件中附件名的代码片段,目前状态基本能用
package org.xkit.mail.demo;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class MailAttachmentFilenameDemo {
public static void main(String[] args) {