Skip to content

Instantly share code, notes, and snippets.

View hanxi's full-sized avatar
:octocat:
Happy Coding!!!

涵曦 hanxi

:octocat:
Happy Coding!!!
View GitHub Profile
@hanxi
hanxi / fork_fork.c
Last active August 29, 2015 13:57
子进程的使用,父进程根据signal监听子进程的退出。预防僵尸进程的两种方法。
#include <stdio.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <unistd.h>
int main(void)
{
pid_t pid;
if ((pid = fork()) < 0)
--[[=============================================================================
# FileName: 2048.lua
# Desc: lua console 2048
# Author: hanxi
# Email: hanxi.info@gmail.com
# HomePage: http://www.hanxi.info
# Version: 0.0.1
# LastChange: 2014-04-28 11:05:09
# History:
=============================================================================]]
@hanxi
hanxi / setconst.lua
Created June 5, 2014 14:06
将lua配置表设置成只读
local rawnext = next
function next(t,k)
local m = getmetatable(t)
local n = m and m.__next or rawnext
return n(t,k)
end
function pairs(t) return next, t, nil end
function readonly(t)
local proxy = {}
@hanxi
hanxi / createtable.sql
Created July 2, 2014 08:54
新浪sae搭建游戏分数排行榜
CREATE TABLE `ScoreRank` (
`Name` varbinary(64) NOT NULL,
`Score` int(11) DEFAULT NULL,
`Level` int(11) NOT NULL DEFAULT '1',
PRIMARY KEY (`Name`,`Level`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- bare-bones luac in Lua
-- usage: lua luac.lua file.lua file.out
local out=arg[1]..".out"
if arg[2]~=nil then out=arg[2] end
f=assert(io.open(out,"wb"))
assert(f:write(string.dump(assert(loadfile(arg[1])))))
assert(f:close())
@hanxi
hanxi / testabc.lua
Last active August 29, 2015 14:05
a+b=c a,b,c都是三位数且不重复
local tostring = tostring
local tonumber = tonumber
local ssub = string.sub
local sformat = string.format
local tconcat = table.concat
local tinsert = table.insert
local si={1,2,3,4,5,6,7,8,9}
function printsi(si)
print(tconcat(si))
@hanxi
hanxi / sslice.c
Created August 16, 2014 09:13 — forked from cloudwu/sslice.c
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct sslice {
const char *ptr;
size_t sz;
};
int
@hanxi
hanxi / split.lua
Created November 21, 2014 02:24
lua string split
function split(str,sep)
local array = {}
local reg = string.format("([^%s]+)",sep)
local tinsert = table.insert
for mem in string.gmatch(str,reg) do
tinsert(array, mem)
end
return array
end
local s = "one;two;;four"
@hanxi
hanxi / httpd.c
Created November 24, 2014 02:59
tinyhttd
/* J. David's webserver */
/* This is a simple webserver.
* Created November 1999 by J. David Blackstone.
* CSE 4344 (Network concepts), Prof. Zeigler
* University of Texas at Arlington
*/
/* This program compiles for Sparc Solaris 2.6.
* To compile for Linux:
* 1) Comment out the #include <pthread.h> line.
* 2) Comment out the line that defines the variable newthread.
@hanxi
hanxi / vimrc
Last active August 29, 2015 14:10
set nocompatible
filetype off
"{{ 插件安装
"git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim
"PluginInstall
"set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'gmarik/Vundle.vim'