Skip to content

Instantly share code, notes, and snippets.

View ignacio's full-sized avatar

Ignacio Burgueño ignacio

View GitHub Profile
@ignacio
ignacio / example_server.lua
Created December 22, 2010 13:51
Route66 example server.
require "luanode.http"
local router = require "route66".new()
router:get("/prompt", function(req, res)
res:writeHead(200, { ["Content-Type"] = "text/plain"})
res:finish(">:")
end)
router:get("/hello/(.+)", function(req, res, user)
res:writeHead(200, { ["Content-Type"] = "text/plain"})
@ignacio
ignacio / gist:974770
Created May 16, 2011 16:25
Redis table with __index metamethod
local fail_safe = {
__index = function(t, command)
error( ("No command defined for %q"):format(tostring(command)) )
end
}
setmetatable(fail_safe, fail_safe)
-- You add commands here (internally)
local commands = {
get = function(t, key)
@ignacio
ignacio / main.html
Created June 2, 2011 17:14
Socket.IO test
<html>
<head>
<title>Test Socket.IO</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script type='text/javascript'>
var socket = new io.Socket('192.168.21.81', {
rememberTransport: false, port: 8080,
connectTimeout: 5000,
@ignacio
ignacio / test_json.lua
Created January 23, 2012 21:46
Files for luatrace issue
require "luarocks.require"
require "json"
local luatrace = require "luatrace"
luatrace.tron()
local t = json.decode[[
{
"friends": [],
"blah": {},
@ignacio
ignacio / await.lua
Created April 2, 2013 13:54
await wrapper using coroutines (related to this gist: https://gist.github.com/creationix/5291866)
function await(continuation)
local coro = coroutine.running()
local result
local async
continuation(function(err, value)
if async == nil then
async = false
result = value
if err then error(err) end
return
@ignacio
ignacio / await2.lua
Created April 2, 2013 15:31
Another take, but more clumsy.
---
-- Fake synchronous functions
local function Sync(fn)
local function make_resumer(co)
return function(...)
return assert(coroutine.resume(co, ...))
end
end
@ignacio
ignacio / paq.sh
Last active August 29, 2015 14:06
Packaging LuaRocks with FPM
#!/bin/bash
#
# Install fpm
#
apt-get install ruby-dev gcc
gem install fpm
# Packing something that uses Make