Skip to content

Instantly share code, notes, and snippets.

View TheLinx's full-sized avatar

Linus TheLinx

  • Stockholm, Sweden
View GitHub Profile
SHELL = /bin/sh
LIBS =
PREFIX = /usr
ALL = src docs examples tests
CLEAN = $(addsuffix -clean,$(ALL))
INSTALL = $(addsuffix -install,$(ALL))
UNINSTALL = $(addsuffix -uninstall,$(ALL))
Note: These are Minecraft server management scripts. They're quite handy.
function tree(num)
local nums = tostring(num)
local lastnum = tonumber(nums:sub(-1))
if lastnum%2 == 0 then
-- even lastnum
if num/2 == 1 then return num end
return {
num = num,
left = 2,
right = tree(num/2)
local s = "abcdefghi"
local ss = string.sub
for n=1,1000000 do
local a,b,c,d,e,f,g,h,i =
ss(s, 1, 1),
ss(s, 2, 2),
ss(s, 3, 3),
ss(s, 4, 4),
ss(s, 5, 5),
ss(s, 6, 6),
#!/usr/bin/env lua
-- _
-- __ ___ __ ___ | |_ _ _ _ __ ___ _ __
-- \ \ /\ / / '_ ` _ \| __| | | | '_ \ / _ \ '__|
-- \ V V /| | | | | | |_| |_| | |_) | __/ |
-- \_/\_/ |_| |_| |_|\__|\__, | .__/ \___|_|
-- |___/|_|
-- public domain code
local usage = [[
usage: %s [--interval #] ([--loop]|[--noloop]) <([file]|[--text "desu"])>
@TheLinx
TheLinx / example.lpx
Created June 25, 2010 13:31
Lua PixMap
return 5, 5, {{255, 255, 255, 255}}, {
{{1, 1, 1, 1, 1},
{0, 0, 0, 1, 0},
{0, 0, 1, 0, 0},
{0, 1, 0, 0, 0},
{1, 1, 1, 1, 1}}
}

Luna

Luna is a template engine that allows the use of Lua code in your templates.
It stays close to the Lua philosophy and is easy to use.

Basic concept

[[ -- this marks the beginning of a Lua code block
pageTitle = "My Awesome Site!"
@TheLinx
TheLinx / printr.lua
Created June 10, 2010 22:57
lua printr
-- this goes in your LUA_PATH, which you can find out by running:
-- lua -e 'print(package.path:sub(22,package.path:sub(22):find("%?%.lua")+20))'
-- first, require("printr")
-- then, use the function printr()
-- this code is public domain
local stringFormat,stringRep,stringChar = string.format,string.rep,string.char
local tableInsert,tableConcat = table.insert,table.concat
local function serializevalue(v, d, n)
-- this goes in your LUA_PATH, which is usually:
-- /usr/share/lua/5.1/
-- /usr/local/share/lua/5.1
-- C:\Program Files\Lua\5.1
-- first, require("printr")
-- then, use the function printr()
-- this code is public domain
local stringFormat,stringRep,stringChar = string.format,string.rep,string.char
local tableInsert,tableConcat = table.insert,table.concat
@TheLinx
TheLinx / md5img
Created May 23, 2010 16:44
md5img
#!/usr/bin/env lua
-- This code is public domain, you may use it however you like.
local md5 = require("md5")
local tonumber = tonumber
local ioOpen,ioRead = io.open,io.read
local osExecute = os.execute
local tableConcat,tableInsert = table.concat,table.insert
if not arg[1] or not arg[2] or not arg[3] then
print("Usage: "..arg[0].." EncodeString OutResolution OutFilename")