Skip to content

Instantly share code, notes, and snippets.

@arch-jslin
arch-jslin / lua_meta.lua
Created February 14, 2011 04:27
Lua: C++ template like example
-- suppose you have a Vec2 and Vec3 type, and a T type which will use them accordingly
-- The Class information should be available out side of this file scope, e.g
-- require 'Vec2'
-- require 'Vec3'
-- require 'Class_with_dimension'
-- I wrote it down here just for simplification
local Vec2 = {}
function Vec2:new(x, y) return setmetatable({x, y}, {__index = self}) end
@arch-jslin
arch-jslin / gist:634137
Created October 19, 2010 12:51
guess_server_script.js
// env, kit 為 server 暴露給開發者用的功能物件
var sys = kit.sys; // 服務管理工具
var game = kit.game; // 遊戲邏輯工具
var db = kit.db; // 資料永續儲存介面
var mem = kit.sharedmem; // shared variable, 跨多個 logic files
var data_ = {}; // user defined local variable
/*
* 1. 覆寫遊戲服務的管理事件, 如 start, stop 等, 沒寫的話 server 會用內建版本
*/
/* list color 字記得改成 416A7A */
pre { margin: 0; }
ol { list-style-type: decimal; }
ol ol, ol ol ol ol, ol ol ol ol ol ol {
list-style-type: none;
counter-reset: item;
margin: 0 0 0 2em;
LOL
@ @@
@@ @ @@
@@ @@ @@@@ @@@
@@@@@@@@@@@
@@@ @@@@
@@@@@@@ @@@ @@@@@
@@@@@@@ @ @@ @@@
@@@@@@@ @@ @@@@ @@ @
<NotepadPlus>
<UserLang name="Scala" ext="scala">
<Settings>
<Global caseIgnored="no" />
<TreatAsSymbol comment="no" commentLine="yes" />
<Prefix words1="no" words2="no" words3="no" words4="no" />
</Settings>
<KeywordLists>
<Keywords name="Delimiters">\&apos;0&quot;&apos;0</Keywords>
<Keywords name="Folder+">{</Keywords>
var memoizer = function (memo, fundamental) {
var make_query = function(args) {
var i = 0, query = '';
for( ; i < args.length - 1 ; i += 1 ) {
query += args[i] + ',';
}
query += args[i]; // i == args.length - 1
return query;
};
var memoizer = function (memo, fundamental) {
var shell = function (n) {
var result = memo[n];
if (typeof result !== 'number') {
result = fundamental(shell, n);
memo[n] = result;
}
return result;
};
return shell;
var fibonacci = function() {
var memo = [0, 1];
var fib = function (n) {
var result = memo[n];
if (typeof result !== 'number') {
result = fib(n - 1) + fib(n - 2);
memo[n] = result;
}
return result;
};
Function.method('curry', function(){
var slice = Array.prototype.slice,
args = slice.apply(arguments),
that = this;
return function(){
var complete_pack = args.concat(slice.apply(arguments));
if( complete_pack.length < that.arity ) {
return that.curry.apply(that, complete_pack);
}
else return that.apply(null, complete_pack);
r = Regexp.new(
'( (http|https|ftp)://)*'+ #protocol:// 可有可無
'( (\d{1,3}\.){3,3}\d{1,3}|'+ #第二段,這邊可能是 IPv4
'((-|\w)+\.)+(tw|com|aero|us|gr)|'+ #或正常suffix的DN
'((-|\w)+\.)*localhost )'+ #或localhost
'(:\d{1,5})?'+ #:port number
'(/\S+)*', Regexp::EXTENDED) #第一個 / 後面就不管他了