Skip to content

Instantly share code, notes, and snippets.

#!/bin/sh
ARIA2_URI=${ARIA2_URI:-127.0.0.1:6800}
[ -n "$ARIA2_SECRET" ] && SECRET='"secret":"$ARIA2_SECRET", '
die() {
[ -n "$1" ] && echo $1
cat << EOF
Usage: $(basename $0) OPTION (VALUE)
Available options:
@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 / auth.lua
Last active June 21, 2017 08:49
nginx rtmp/hls server setup
-- add users:
-- $ htpasswd -s -c /etc/nginx-rtmp/.htpasswd streamname
-- stream:
-- $ ffmpeg -i foo.mp4 -c copy -f flv rtmp://abc.de/streamname?auth=password
local users = {}
for line in io.lines("/etc/nginx-rtmp/.htpasswd") do
local user, pass = line:match("([^:]+):{SHA}([^\n]+)")
users[user] = pass
end
@fur-q
fur-q / host.c
Created January 25, 2016 00:52
luajit script host
#include <stdio.h>
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#define DIE(e) do { fprintf(stderr, "FATAL: %s\n", e); return 1; } while (0)
static void l_getargs(lua_State * L, int argc, const char ** argv) {
int i;
lua_newtable(L);
@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 / 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 / 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 / assert.lua
Last active November 26, 2015 15:19
local asr = {}
function asr.equal(a, b) return a == b end
function asr.error(fn, ...) local ok, out = pcall(fn, ...) return (not ok) and out end
function asr.match(a, b) return tostring(a):match(b) end
function asr.type(a, b) return type(a) == b end
local mt = {}
function mt.__index(t, k)
if not asr[k] then return end
return function(...)
@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 / 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