Skip to content

Instantly share code, notes, and snippets.

@mascarenhas
mascarenhas / hello.lua
Created April 14, 2011 01:58
Proof of concept for FastCGI handler with helper threads
#!/usr/bin/env lua
-- Example application for the FastCGI handler with helper threads
local fastcgi = require "thfcgi"
local hello = {}
local heartbeat = [[
local zmq = require "zmq"
@mascarenhas
mascarenhas / songs.lua
Created March 8, 2010 21:06
"Hello World" for the mk framework and its theme system
#!/usr/bin/env wsapi.cgi
local mk = require "mk"
local R = require "mk.routes"
local request = require "wsapi.request"
local response = require "wsapi.response"
local cosmo = require "cosmo"
local template = require "mk.template"
local themes = require "mk.themes"
local lpeg = require "lpeg"
local re = require "re"
local json = require "json"
local P = lpeg.P
local S = lpeg.S
local R = lpeg.R
local C = lpeg.C
local Ct = lpeg.Ct
local done_recently = todo_list:find_all("done = ? and updated_at >= ?",
{ true, os.time{ year = 2009, month = 11, day = 01 }, order = "created_at desc" })
for _, item in ipairs(done_recently) do
print(item.title)
end
local item = todo_list:new()
item.title = "Todo Item"
item.done = true
item:save()
assert(item.id ~= nil)
local todo = orbit.model.new()
todo.conn = luasql.sqlite3()::connect("todo.db")
local todo_list = todo:model("todo_list")
#!/usr/bin/env wsapi.cgi
require "orbit"
require "orbit.routes"
local R = orbit.routes.R
local hello = orbit.new()
hello:dispatch_get(function (web)
require "orbit"
require "orbit.routes"
local R = orbit.routes.R
local hello = orbit.new()
hello:dispatch_get(function (web)
return string.format('<h1>Welcome to %s!</h1>', web.real_path)
#!/usr/bin/lua
pcall(require,"luarocks.require")
local common = require "wsapi.common"
local fastcgi = require "wsapi.fastcgi"
local ONE_HOUR = 60 * 60
local ONE_DAY = 24 * ONE_HOUR
local env = luasql.sqlite3()
local db = todo.real_path .. "/todo.db"
local timeout = 3600 -- one hour
todo.mapper.conn = recycle(function ()
return env:connect(db)
end, timeout)