Skip to content

Instantly share code, notes, and snippets.

View kingluo's full-sized avatar

jinhua luo kingluo

View GitHub Profile
@kingluo
kingluo / c.c
Created July 8, 2015 08:56
cgo good example
#include "c.h"
#include "_cgo_export.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
struct A* echo(void) {
const char* p = "hello world";
GoString p2;
p2.p = (char*)p;
@kingluo
kingluo / pipe.go
Last active August 29, 2015 14:24
go socks5
package pipe
import (
"fmt"
"net"
)
func ConnPipe(c1 net.Conn, c2 net.Conn) {
defer c1.Close()
defer c2.Close()
@kingluo
kingluo / perm.erl
Last active August 29, 2015 14:24
math example: combination
-module(perm).
-export([main/1]).
iend(M, N, Level) ->
Room = N - Level,
M - Room.
for(S, E, F) when S =< E -> F(S), for(S + 1, E, F);
for(_, _, _) -> void.
@kingluo
kingluo / processes.erl
Last active July 7, 2023 08:19
erlang noshell
$ erlc processes.erl
$ erl -noshell -s processes test -s init stop
the max processes is 262144
the proecess time is 2.0:3.57
$ erl -noshell -s processes test2 100000 -s init stop
the max processes is 262144
{"init terminating in do_boot",{system_limit,[{erlang,spawn,[erlang,apply,[#Fun<processes.2.26012808>,[]]],[]},{erlang,spawn,1,[]},{processes,for,3,[{file,"processes.erl"},{line,24}]},{processes,for,3,[{file,"processes.erl"},{line,24}]},{processes,max,1,[{file,"processes.erl"},{line,10}]},{init,start_it,1,[]},{init,start_em,1,[]}]}}
# program freeze here...
# Ctrl+C not work
@kingluo
kingluo / test.c
Created June 26, 2015 08:10
lua_newstate vs lua_newthread
$ gcc -o test test.c -llua -lm -ldl
$ time ./test state
real 0m21.470s
user 0m20.472s
sys 0m0.980s
$ time ./test
@kingluo
kingluo / coroutine.lua
Created June 18, 2015 09:00
coroutine reuse
-- Copyright (C) Jinhua Luo
local ffi = require("ffi")
local timer = require("ljio.core.timer")
local epoll = require("ljio.core.epoll")
local add_timer = timer.add_timer
local tremove = table.remove
local tinsert = table.insert
local pairs = pairs
@kingluo
kingluo / buf.lua
Created April 6, 2015 12:54
who can explain the -jv output in detail?
-- Copyright (C) Jinhua Luo
local select = select
local type = type
local tostring = tostring
local ipairs = ipairs
local tinsert = table.insert
local tremove = table.remove
local tpool = {n = 0}
@kingluo
kingluo / gist:0189aad79b0b081a0526
Created April 3, 2015 13:16
luajit.io -jv output (luajit 2.1)
https://github.com/kingluo/luajit.io/tree/tmp
[TRACE 1 init.lua:602 stitch string.gmatch_aux]
[TRACE 2 init.lua:602 stitch string.gmatch_aux]
[TRACE 3 init.lua:601 stitch string.gmatch]
[TRACE 4 init.lua:602 stitch string.gmatch_aux]
[TRACE 5 init.lua:602 -> 1]
[TRACE 6 (2/0) init.lua:602 -> 1]
fork worker pid=10381
[TRACE 7 init.lua:158 loop]