This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
solution 'lua' | |
configurations {'Debug', 'Release'} | |
platforms {'x32', 'x64'} | |
if os.get() == "windows" then | |
defines '_CRT_SECURE_NO_WARNINGS' | |
end | |
-- the lua library | |
project 'lualib' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BaseConstructor | |
{ | |
static class Base | |
{ | |
{ | |
System.out.println("Base initialize block"); | |
} | |
Base() | |
{ | |
System.out.println("Base()"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | |
-- 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use diagnostics; | |
use warnings; | |
use sigtrap; | |
my $name = "**value**"; | |
# q = single quote | |
print q('hello, world'); | |
print "\n"; | |
print q("hello, world"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |