This file contains 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
#include <lua.h> | |
#include <lauxlib.h> | |
#include <ltable.h> | |
#include <lstate.h> | |
#include <lobject.h> | |
#include <stdio.h> | |
#include <string.h> | |
#define MAGIC_VECTOR 1.23456789 |
This file contains 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 mingw in windows | |
// gcc -O2 -o utf8.exe utf8to16.c | |
#include <stdio.h> | |
#include <fcntl.h> | |
#include <io.h> | |
#include <wchar.h> | |
static const char trailingBytesForUTF8[256] = { | |
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | |
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, |
This file contains 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
// gcc -g -Wall -o alloc alloc.c | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <assert.h> | |
#include <string.h> | |
#if defined(_MSC_VER) || defined(__MINGW32__) || defined(__MINGW64__) | |
#include <windows.h> |
This file contains 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
/** | |
* $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" |
This file contains 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
-- 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 |
This file contains 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
#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) |
This file contains 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
#include <stdio.h> | |
#include <stdlib.h> | |
#include <time.h> | |
#include <assert.h> | |
struct memnode { | |
struct memnode * next; | |
}; | |
struct fixalloc { |
This file contains 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 skynet = require "skynet" | |
local socket = require "socket" | |
local mode , id = ... | |
local function echo(id) | |
socket.start(id) | |
skynet.error("start", id) | |
while true do |
This file contains 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 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+) ([^ ]+)") |
This file contains 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 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 |