Skip to content

Instantly share code, notes, and snippets.

View richardhundt's full-sized avatar

Richard Hundt richardhundt

View GitHub Profile
@richardhundt
richardhundt / ray.c
Created February 24, 2013 11:01
libray
#include "ray.h"
int ray_last_error(ray_ctx_t* self) {
uv_err_t err = uv_last_error(self->loop);
return err.code;
}
const char* ray_strerror(int code) {
uv_err_t err = { .code = code };
return uv_strerror(err);
}
@richardhundt
richardhundt / codegen.lua
Created December 1, 2012 07:29
LuaJIT 2 bytecode generator
--[=[
dump = header proto+ 0U
header = ESC 'L' 'J' versionB flagsU [namelenU nameB*]
proto = lengthU pdata
pdata = phead bcinsW* kgc* knum* uvdataH* [debugB*]
phead = flagsB numparamsB framesizeB numuvB numkgcU numknU numbcU
[debuglenU [firstlineU numlineU]]
kgc = kgctypeU { ktab | (loU hiU) | (rloU rhiU iloU ihiU) | strB* }
knum = intU0 | (loU1 hiU)
ktab = narrayU nhashU karray* khash*
@richardhundt
richardhundt / httpd-k.lua
Created October 9, 2012 07:37
http server with keep-alive
ocal luv = require('luv')
local response_html = "<p>Hello, world!</p>"
local response_size = #response_html
local http_response = "HTTP/1.0 200 OK\r\
Content-Type: text/html\r\
Content-Length: "..tostring(response_size).."\r\
Connection: Keep-Alive\r\
\r\
"..response_html