Skip to content

Instantly share code, notes, and snippets.

View cloudwu's full-sized avatar

云风 cloudwu

View GitHub Profile
@cloudwu
cloudwu / lmd5.c
Last active November 30, 2018 13:56
lua md5 mod
/**
* $Id: md5.c,v 1.2 2008/03/24 20:59:12 mascarenhas Exp $
* Hash function MD5
* @author Marcela Ozorio Suarez, Roberto I.
*/
#include <string.h>
//#include "md5.h"
@cloudwu
cloudwu / deepcopy.lua
Created October 12, 2016 07:21
deep copy lua table
-- deepcopy a lua table, no recursion sub table, the key never be a table.
local function _copy(obj, target)
local n = 0
-- clear target table
for k,v in pairs(target) do
if type(v) == "table" then
v.__del = true
n = n + 1
else
@cloudwu
cloudwu / float.c
Created October 10, 2016 05:25
float
#include <stdio.h>
int
main() {
double f = 1.0/3.0;
double f2;
char tmp[100];
sprintf(tmp, "%lf", f);
sscanf(tmp, "%lf", &f2);
printf("f = %lf f2 = %lf , %d\n", f, f2, (f2 == f)); // should be 0 (false)
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <assert.h>
struct memnode {
struct memnode * next;
};
struct fixalloc {
@cloudwu
cloudwu / testsocket.lua
Created May 18, 2016 10:51
skynet socket transfor
local skynet = require "skynet"
local socket = require "socket"
local mode , id = ...
local function echo(id)
socket.start(id)
skynet.error("start", id)
while true do
@cloudwu
cloudwu / memlog.lua
Last active July 27, 2017 12:15
Convert malloc log
local yield = coroutine.yield
local function loadlog(filename)
-- local log = {}
local f = assert(io.open(filename))
for line in f:lines() do
if line == "=======" then
break
end
local ptr, osize, nsize, ret = line:match("([^ ]+) (%d+) (%d+) ([^ ]+)")
@cloudwu
cloudwu / searchpath.lua
Created November 6, 2015 05:31
Lua version package.searchpath
local DIRSEP, PATSEP, MARK = package.config:match "(.-)\n(.-)\n(.-)\n"
MARK = MARK:gsub(".", function (c) return "%" .. c end)
-- todo: replace your own readable function
local function readable(filename)
local f = io.open(filename)
if f then
f:close()
return true
end
@cloudwu
cloudwu / mymod.user.lua
Created October 26, 2015 12:05
user defined loader
local M = {}
function M.test(...)
print(...)
end
return M
@cloudwu
cloudwu / testtun.lua
Last active September 23, 2017 09:58
A timeout tunnel service (skynet)
local skynet = require "skynet"
require "skynet.manager"
local mode = ...
if mode == "slave" then
skynet.start(function()
skynet.dispatch("lua", function(session, address, ti, ...)
if session == 0 then
@cloudwu
cloudwu / inject.lua
Last active March 28, 2023 16:33
Inject code with locals and upvalues
local FUNC_TEMP=[[
local $ARGS
return function(...)
$SOURCE
end,
function()
return {$LOCALS}
end
]]