Skip to content

Instantly share code, notes, and snippets.

View catwell's full-sized avatar

Pierre Chapuis catwell

View GitHub Profile
@catwell
catwell / lima-lua-style-1-general.md
Last active August 21, 2022 15:24
Lima Lua style

Lima Lua style guide

About this style guide

How to read this style guide

Refer to RFC 2119 to interpret MUST, SHOULD and MAY.

Inspiration

@catwell
catwell / wireguard-kernel-conf.sh
Created May 28, 2017 09:33
Print kernel configuration that matters to WireGuard
#!/bin/sh
p () {
zcat /proc/config.gz | grep "$1="
}
p CONFIG_NET
p CONFIG_INET
p CONFIG_NET_UDP_TUNNEL
p CONFIG_NF_CONNTRACK
@catwell
catwell / instance-module.lua
Created January 25, 2017 11:37
Lua templates
--- Instance-based module template.
-- @module example
local methods = {}
local MT = { __index = methods }
local function new()
local self = {}
return setmetatable(self, MT)
diff --git a/src/lmathlib.c b/src/lmathlib.c
index 4f2ec60..d87536d 100644
--- a/src/lmathlib.c
+++ b/src/lmathlib.c
@@ -183,7 +183,7 @@ static int math_log (lua_State *L) {
res = l_mathop(log)(x);
else {
lua_Number base = luaL_checknumber(L, 2);
-#if !defined(LUA_USE_C89)
+#if defined(LUA_USE_LOG2)

Lua devroom request for FOSDEM 2017

Description

Lua [1] is a lightweight multi-paradigm dynamic programming language, designed with embeddability and extensibility as its primary goals. It has a diverse range of uses across industries, including notaby video games, networking and machine learning.

The Lua community holds a yearly Workshop, which will take place mid-October

> x = string.dump(function() end)
> x = x:sub(1,3) .. "b" .. x:sub(5) -- break header
> loadstring(x)()
stdin:1: attempt to call a nil value
stack traceback:
stdin:1: in main chunk
[C]: ?
> assert(loadstring(x))()
stdin:1: binary string: bad header in precompiled chunk
stack traceback:
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=45 time=75.0 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=45 time=57.1 ms
64 bytes from 8.8.8.8: icmp_seq=4 ttl=45 time=41.5 ms
64 bytes from 8.8.8.8: icmp_seq=5 ttl=45 time=39.4 ms
64 bytes from 8.8.8.8: icmp_seq=6 ttl=45 time=42.9 ms
64 bytes from 8.8.8.8: icmp_seq=8 ttl=45 time=69.9 ms
64 bytes from 8.8.8.8: icmp_seq=9 ttl=45 time=49.6 ms
64 bytes from 8.8.8.8: icmp_seq=10 ttl=45 time=37.7 ms
64 bytes from 8.8.8.8: icmp_seq=12 ttl=45 time=40.0 ms
@catwell
catwell / day1.sh
Last active December 7, 2015 08:15
Advent of Code (http://adventofcode.com/) in Bash and Lua.
c=0; n=1
for i in $(fold -b1 $1); do
[ "$i" = "(" ] && c=$((c+1))
[ "$i" = ")" ] && c=$((c-1))
echo $c $n
n=$((n+1))
done
# sh day1.sh input.txt | tail -n1 | cut -d' ' -f1
# sh day1.sh input.txt | grep -e '-1 ' | head -n1 | cut -d' ' -f2
@catwell
catwell / mp_magic.lua
Last active October 30, 2015 10:10
mp_magic
-- For use with https://github.com/fperrad/lua-MessagePack
-- Usage:
-- local mp = require "MessagePack"
-- local MP = mp_magic(mp)
-- mp.pack{ this_is_a_string = MP{binary = "this_is_a_binary"} }
local mp_magic = function(mp)
if mp.mpmagic then return mp.mpmagic end
local mp_mt = {}
local new = function(t) return setmetatable(t, mp_mt) end