Skip to content

Instantly share code, notes, and snippets.

View stuartpb's full-sized avatar

Stuart P. Bentley stuartpb

View GitHub Profile
@stuartpb
stuartpb / lasi.rst
Created January 25, 2011 13:07 — forked from leafstorm/lasi.rst

Lua Application/Server Interface version 0.3.0

Authors

Matthew "LeafStorm" Frazier <leafstormrush@gmail.com>, Stuart P. Bentley <stuart@testtrack4.com>

Date

January 26, 2011

Status

Early draft

This document specifies an interface between Web servers and Web applications written in the Lua programming language, to promote interoperability between Web servers and the development of an ecosystem of reusable components for Lua on the Web.

@stuartpb
stuartpb / redirect.md
Created January 31, 2011 14:20
A page of combined documentation for SDL_ScanCode and SDLKey.
@stuartpb
stuartpb / arbase.lua
Created February 2, 2011 02:45
Function for using arbitrary digit systems to convert numbers to strings
local function base (digit_list)
local b = #digit_list
if b == 0 then
return function(number) return "" end
elseif b == 1 then
local mark = digit_list[1]
return function(number)
return string.rep(mark, number)
end
else
--The values used to represent trees, fires, and empty space.
local TREE = 'T'
local BURNING = '#'
local EMPTY = ' '
--Returns a table with gettors and settors for 2D coordinates.
--This implementation uses a single underlying 1-dimensional
--array table. It could also be changed to use a 2-dimensional
--table of row/column tables, or a table with serialized coordinates.
local function array2d(w,h)
@stuartpb
stuartpb / phone.txt
Created April 9, 2011 04:50
The layout of my phone's voice message system.
To listen to your messages, press 1.
To send a message, press 2.
To change your personal options, press 4.
> Personal options.
To turn message waiting indicator on or off, press 1.
- Message waiting indicator on.
To turn message waiting indicator off, press 2.
> Message waiting indicator now off.
: Personal options.
To exit, press *.
--table of Windows Time Display Notation specifiers
--(http://support.microsoft.com/kb/307938) to the equivalent
--format specifiers for the Visual C++ Runtime Library's
--version of strftime (http://msdn.microsoft.com/en-us/library/fe06s4ak.aspx).
local wtdn2sftf = {
--'t' does only the first character of %p:
--no strftime equivalent
tt = 'p',
H = '#H',
@stuartpb
stuartpb / gist:961903
Created May 9, 2011 01:47
11 Lines of Lua About 88 Lines About 44 Women
lines=[[
Deborah was a Catholic girl
she held out till the bitter end
Carla was a different type
she's the one who put it in
Mary was a black girl
I was afraid of a girl like that
Suzen painted pictures
sitting down like a Buddha sat
@stuartpb
stuartpb / gist:975183
Created May 16, 2011 19:47
Counts the occurrences of a phrase in an RFC
local src = http.request"http://tools.ietf.org/id/draft-ietf-ldapext-ldap-c-api-05.txt"
src = string.gsub(src,[[
Expires: May 2001 -%[Page %d+%]
C LDAP API -C LDAP Application Program Interface -17 November 2000]],"\n")
local function count(pat)
return select(2,string.gsub(src,pat,""))
end
local function plain(str)
@stuartpb
stuartpb / example.lua
Last active December 14, 2021 18:11
Lua script for fancy named parameters with default values
local fp = require "fancyparams"
myfunction = fp(
{{"a"},{"b",7},{"c",5}},
function(a, b, c)
print(a, b, c)
end
)
@stuartpb
stuartpb / osfacopy.lua
Created May 25, 2011 15:29
Monstrous one-size-fits-all Lua table copy
return function (t,o)
local refs = {}
local rk, rv
if type(o.recurse) == "string" then
if string.find(o.recurse,'k') then
rk = true end
if string.find(o.recurse,'v') then
rv = true end
elseif o.recurse then
rk=true; rv=true