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 / generate.lua
Created November 9, 2012 12:42 — forked from chenshuo/query_freq.cc
Sort queries by their frequencies.
-- this version is very slow, as every time we update the buffer, we creating a new string, which
-- makes the original buffer unreferenced. and lua's gc will kicks in often to clean up memory
-- which is really realy slow.
local file = io.open("file.txt", "w")
local buffer = ''
for i = 1, 500000000 do
local n = i % math.random(10000)
local str = string.format("This is a number %d\n", n)
buffer = buffer .. str -- make the original string buffer unreferenced
if i % 10000 == 0 then
@baiyanhuang
baiyanhuang / lua-premake4.lua
Created October 28, 2012 05:30
lua script to build lua 5.2.1
solution 'lua'
configurations {'Debug', 'Release'}
platforms {'x32', 'x64'}
if os.get() == "windows" then
defines '_CRT_SECURE_NO_WARNINGS'
end
-- the lua library
project 'lualib'
// The code below would print overlapped A and B sequences like:
// ...
// A
// A
// B
// B
// ...
//
// Please add multi-threading protection code to make sure that
// As and Bs are printed in the order of:
@baiyanhuang
baiyanhuang / palindromelist.cpp
Created September 14, 2012 09:05
Given a circular single linked list and the start pointer, check if it is a palindrome
/**
* Given a circular single linked list and the start pointer, check if it is a palindrome
* use a slow/fast pointer + stack is an elegant way
* tip: wheneve there is a circular linked list, think about using slow/fast pointer
*/
#include <iostream>
#include <stack>
using namespace std;
@baiyanhuang
baiyanhuang / BaseConstructor.java
Created August 30, 2012 14:36
Test the derived constructor, base constructor and initialization block calling sequence
class BaseConstructor
{
static class Base
{
{
System.out.println("Base initialize block");
}
Base()
{
System.out.println("Base()");
@baiyanhuang
baiyanhuang / popoverhold.html
Created August 17, 2012 07:40
bootstrap's popover plugin, hold the tip until move leave.
<head language="en">
<meta charset="utf-8">
<title> bootstrap testing</title>
<link href="bootstrap/css/bootstrap.css" rel="stylesheet">
<script src="jquery-1.7.2.js"> </script>
<script src="bootstrap/js/bootstrap.js"> </script>
<style type="text/css">
.myClass{ position: relative;}
</style>
</head>
@baiyanhuang
baiyanhuang / largestsum.lua
Created August 16, 2012 15:58
Given an array, get the sub sequence that of larget sum.
--
-- Given an array, get the sub sequence that of larget sum.
--
function printArray(array)
for i=1, #array do
io.write(array[i]) -- parameter is a variable, () can't be ignored.
io.write(" ")
end
end
@baiyanhuang
baiyanhuang / quoted-x.pl
Created July 30, 2012 14:53
testing q, qq, qw, qr, qx
use strict;
use diagnostics;
use warnings;
use sigtrap;
my $name = "**value**";
# q = single quote
print q('hello, world');
print "\n";
print q("hello, world");
@baiyanhuang
baiyanhuang / ProxyTest.java
Created July 19, 2012 03:31
Test java's dynamic proxy class - to avoid boilplate wrapper code for all classes
package baiyanhuang;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Arrays;
import java.util.Random;
/**
* Learn Java's dynamic proxy (in reflection)
@baiyanhuang
baiyanhuang / initarray.cpp
Created July 18, 2012 08:36
You can only initialize array on declaration for stack variables
#include <iostream>
using namespace std;
int main()
{
// initialize stack array variable
int x[] = {1, 3, 4};
int b[][2] = {{1, 2}, {3, 4}};