Skip to content

Instantly share code, notes, and snippets.

View hpcx82's full-sized avatar

hpcx hpcx82

  • Shanghai
View GitHub Profile
@hpcx82
hpcx82 / CMakeLists.txt
Created November 11, 2012 07:49
Build lua with cmake
cmake_minimum_required (VERSION 2.6)
project (lua) # project here actually means solution in premake
if(WIN32)
add_definitions( -D_CRT_SECURE_NO_WARNINGS )
endif()
# 1. lua static library
# how to rename library name?
add_library (lualib STATIC lapi.c lcode.c lctype.c ldebug.c ldo.c ldump.c lfunc.c lgc.c llex.c lmem.c lobject.c lopcodes.c lparser.c lstate.c lstring.c ltable.c ltm.c lundump.c lvm.c lzio.c lauxlib.c lbaselib.c lbitlib.c lcorolib.c ldblib.c liolib.c lmathlib.c loslib.c lstrlib.c ltablib.c loadlib.c linit.c)
@hpcx82
hpcx82 / 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
@hpcx82
hpcx82 / 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:
@hpcx82
hpcx82 / 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;
@hpcx82
hpcx82 / 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()");
@hpcx82
hpcx82 / 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>
@hpcx82
hpcx82 / 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
@hpcx82
hpcx82 / 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");
@hpcx82
hpcx82 / 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)