Skip to content

Instantly share code, notes, and snippets.

View daurnimator's full-sized avatar

daurnimator

View GitHub Profile
@daurnimator
daurnimator / autolua.zig
Last active May 9, 2021 05:12
Lua binding creator in zig
const std = @import("std");
const assert = std.debug.assert;
const lua_ABI = @cImport({
@cInclude("lua.h");
@cInclude("lauxlib.h");
@cInclude("lualib.h");
});
pub const lua = struct {
@daurnimator
daurnimator / sendsms.lua
Created February 28, 2016 11:11
Lua lib to send SMS with Telstra's SMS API
local telstra_sms_api = require "telstra_sms_api".new
local sleep = require "cqueues".sleep
if #arg < 2 then
io.stderr:write("Expected number and body\n")
os.exit(1)
end
local to = arg[1]
local message = table.concat(arg, " ", 2)
@daurnimator
daurnimator / ThreadPool.zig
Last active January 3, 2021 18:09 — forked from kprotty/ThreadPool.zig
simple http server compatible with wrk for linux using epoll
const std = @import("std");
const system = switch (std.builtin.os.tag) {
.linux => std.os.linux,
else => std.os.system,
};
const ThreadPool = @This();
max_threads: u16,
counter: u32 = 0,
@daurnimator
daurnimator / cqueues-fifo.lua
Created March 17, 2015 21:13
Wrapper around fifo.lua using cqueues to implement non-blocking queues.
local new_fifo = require "fifo"
local cqueues = require "cqueues"
local cc = require "cqueues.condition"
local methods = {}
local mt = {
__index = methods;
}
function methods.new(...)
local cond = cc.new();
local strbyte = string.byte
local bit = require"bit"
local band = bit.band
local bor = bit.or
local lshift = bit.lshift
local rshift = bit.rshift
local function utf8_to_codepoint ( s , i )
local x = strbyte ( s , i , i )
#include <errno.h>
#include <stdio.h>
#include <unistd.h>
#include <netinet/tcp.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/socket.h>
int main(int argc, char **argv) {
int s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

Compatible with Lua 5.3

// zig test bls.zig -I/usr/include -lc -lstdc++ -L/usr/lib -lbls_c256
const std = @import("std");
const assert = std.debug.assert;
const testing = std.testing;
const BLS = struct {
const curves = enum {
bls_c256,
bls_c384,
@daurnimator
daurnimator / tarantool-websockets.lua
Created February 15, 2018 04:11
Tarantool + lua-http websockets nonblocking
#!/usr/bin/env tarantool
local cqueues = require "cqueues"
local fiber = require "fiber"
local socket = require "socket"
package.loaded["http.client"] = nil -- tarantool has a namespace clash
local websocket = require "http.websocket"
local cq = cqueues.new()
-- Hook up cqueues loop inside tarantool fiber
@daurnimator
daurnimator / luarocks-0.1.template
Created October 20, 2019 13:41
luarocks draft makepkg-template
pkgname=("lua-$_rockname" "lua51-$_rockname" "lua52-$_rockname")
makedepends+=('luarocks' 'lua' 'lua51' 'lua52')
build() {
for lua_ver in 5.1 5.2 5.3; do
mkdir -p "$lua_ver"
(cd "$lua_ver"; luarocks build --pack-binary-rock --lua-version="$lua_ver" --deps-mode=none --no-manifest "$_rockname"-"$pkgver"-*.rockspec)
done
}