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
#!/usr/bin/lua | |
function gf_CopyTable(tbOrg) | |
local tbSaveExitTable = {} | |
local function _copy(object) | |
if type(object) ~= "table" then | |
return object; | |
elseif tbSaveExitTable[object] then --检查是否有循环嵌套的table | |
return tbSaveExitTable[object]; | |
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
local M = {} | |
function M.test(...) | |
print(...) | |
end | |
return M |
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
var Queue = function() { | |
this.tail = []; | |
this.head = []; | |
this.offset = 0; | |
}; | |
module.exports = Queue; | |
Queue.prototype.shift = function () { | |
if (this.offset === this.head.length) { |
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
var MT = []; | |
var index = 0; | |
function initialize_generator(seed) { | |
MT[0] = seed; | |
for (var i = 1; i < 624; i++) { | |
MT[i] = 0xffffffff & (0x6c078965 * (MT[i - 1] ^ (MT[i - 1] >> 30)) + i); | |
} | |
} | |
function generate_numbers() { | |
for (var i = 0; i < 624; i++) { |
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
var Ws = require('ws').Server; | |
var num = 0; | |
var server = new Ws({ port: 4000 }); | |
server.on('connection', function(client) { | |
client.addEventListener('message', function(msg) { | |
// no thing to do | |
}); | |
++num; | |
console.log('new comer = ', num); | |
}); |
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
var WS = require('ws'); | |
var cli = []; | |
function send() { | |
var str = 'I am ok!'; | |
var len = Buffer.byteLength(str); | |
var buf = new Buffer(len + 2); | |
buf.writeUInt16LE(len, 0); | |
buf.write(str, 2, len); | |
this.send(buf); | |
} |
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
--[[ | |
onlytcp lua客户端 | |
因为发现luasocket receive(number)方式的一个奇惨问题 所以收数据改成了按行读取 | |
]] | |
CONST_Socket_TickTime = 0.1--SOCKET接收信息轮训时间 | |
CONST_Socket_ReconnectTime = 5--socket重连偿试时间时隔 | |
CONST_HeartBeaT_TimeOut = 20--socket心跳超时时间 | |
CONST_HeartBeaT_SendTime = 15--socket心跳发送间隔 | |
CONST_HeartBeaT_CheckTime = 25--socket心跳检查时间 |
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
--复制一个table | |
--org为源table,des为复制出来的新table | |
function gf_CopyTable(tbOrg) | |
local tbSaveExitTable = {} | |
local function _copy(object) | |
if type(object) ~= "table" then | |
return object | |
elseif tbSaveExitTable[object] then --检查是否有循环嵌套的table | |
return tbSaveExitTable[object] | |
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
local IA = 3877 | |
local IB = 29573 | |
local g_seed = 42 | |
function setseed(seed) | |
g_seed = seed | |
end | |
function getrandom(max) |
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
--[[ | |
天干纪年,格里历 | |
其实只能正确计算 1752年9月14日之后的,因为1752年9月被英国议会去掉了11天,前面的历法计算需要换用儒略历,太过复杂 | |
]] | |
local tbHeavenlyStems = { --天干 | |
[1] = "甲", | |
[2] = "乙", | |
[3] = "丙", |