Skip to content

Instantly share code, notes, and snippets.

@fur-q
fur-q / app.lua
Created September 14, 2012 12:03
shorty
require "shorty"
shorty:get("/", function()
local args = { title = "test", content = "IT WORKS" }
return render("index", args)
end)
shorty:get("/headers", function()
local out = {}
for k,v in pairs(req.headers) do
@fur-q
fur-q / main.lua
Created October 10, 2012 01:19
stop using module() ok
local mod = require "mod"
print(mod.func, mod.x)
-- 100, function: 0xFFFFFFFF
print(mod.priv, priv)
-- nil, nil
@fur-q
fur-q / Makefile
Last active December 14, 2015 03:29
example C extension for Lua
PC = pkg-config
LUA = lua5.1
CFLAGS = `$(PC) --cflags $(LUA)` -Wall -fPIC
LDFLAGS = `$(PC) --libs $(LUA)`
lsleep.so: lsleep.c
gcc -shared $(CFLAGS) $(LDFLAGS) -o $@ $^
clean:
-rm lsleep.so
@fur-q
fur-q / config.cfg
Last active December 14, 2015 06:59
the best lua config loader idst
hostname = "localhost"
reconnect = true
attempts = 10
ignore = { "user1", "user2" }
channels = {}
for i = 1, 4 do
channels[i] = "#channel" .. i
end
@fur-q
fur-q / irc.c
Created December 13, 2013 04:30
libircclient and a proper event loop (specifically ae)
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <sys/select.h>
#include "libircclient.h"
#include "ae.h"
typedef struct irc_fds_t {
fd_set rfd, wfd;
} irc_fds_t;
@fur-q
fur-q / main.c
Last active October 10, 2017 06:47
C/Lua interop basic example
static int cf_tolua(lua_State *L) {
lua_pushliteral(L, "hello");
return 1;
}
static int cf_fromlua(lua_State *L) {
const char *str = lua_tostring(L, 1); // first argument passed in; second would be at index 2
printf("%s\n", str);
return 0;
}
@fur-q
fur-q / pp.lua
Last active August 29, 2015 14:02
it is a prettyprinter
local function prettyprint(t, l)
l = l or 0
for k, v in pairs(t) do
io.write(string.rep(" ", (l * 4)), k, " = ")
if type(v) == "table" then
io.write("table:\n")
prettyprint(v, l+1)
else
io.write(tostring(v), "\n")
end
@fur-q
fur-q / url.lua
Last active August 29, 2015 14:02
local function parse_url(url)
local out = {}
url = string.gsub(url, "#(.*)$", function(f)
out.fragment = f
return ""
end)
url = string.gsub(url, "^([%w][%w.+-]*):", function(s)
out.scheme = s
return ""
end)
@fur-q
fur-q / Makefile
Last active August 29, 2015 14:06
im da bes
CC = gcc
LUA = luajit
loader: loader.o myscript.l.o
$(CC) $(LDFLAGS) -o $@ $^
%.l.o: %.lua
$(LUA) -bg $^ $@
@fur-q
fur-q / youtune.sh
Last active August 29, 2015 14:16
audio + picture -> youtube upload script
#! /bin/sh
error() {
echo >&2 "$1"
exit 1
}
required() {
command -v "$1" >/dev/null 2>&1 || error "$1 required but not installed; quitting"
}