Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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(...)
#!/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 / imgur.lua
Last active August 29, 2015 14:16
imgur hilarity finder for best laughs time
-- $ lua imgur.lua abcde [fghij]
local leet = {
["o"] = 0, ["i"] = 1, ["e"] = 3, ["a"] = 4, ["s"] = 5, ["t"] = 7
}
local teel = {
[0] = "O", [1] = "I", [3] = "E", [4] = "A", [5] = "S", [7] = "T"
}
@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"
}
@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 / 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 / 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 / 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;
}