Skip to content

Instantly share code, notes, and snippets.

@enotodden
enotodden / s.py
Last active November 20, 2021 10:05
Command line string replace with Python regex and format strings.
#!/usr/bin/env python
import os
import sys
import re
import argparse
if sys.version_info.major == 3:
from io import StringIO
else:
from StringIO import StringIO
@enotodden
enotodden / helloworld.lua
Created June 28, 2013 22:36
Turbo 'Hello World'.
local turbo = require("turbo")
-- Create a new requesthandler with a method get() for HTTP GET.
local HelloWorldHandler = class("HelloWorldHandler", turbo.web.RequestHandler)
function HelloWorldHandler:get()
self:write("Hello World!")
end
-- Create an Application object and bind our HelloWorldHandler to the route '/hello'.
local application = turbo.web.Application:new({
@enotodden
enotodden / hello_name.lua
Created June 30, 2013 00:01
Turbo request parameters example.
local turbo = require("turbo")
local HelloNameHandler = class("HelloNameHandler", turbo.web.RequestHandler)
function HelloNameHandler:get()
-- Get the 'name' argument, or use 'Santa Claus' if it does not exist
local name = self:get_argument("name", "Santa Claus")
self:write("Hello " .. name .. "!")
end
@enotodden
enotodden / hello_json.lua
Created June 30, 2013 00:20
Turbo implicit JSON output example.
local turbo = require("turbo")
local HelloJSONHandler = class("HelloJSONHandler", turbo.web.RequestHandler)
function HelloJSONHandler:get()
self:write({hello="json"})
end
local application = turbo.web.Application:new({
{"/hello", HelloJSONHandler}
})
@enotodden
enotodden / routes_example.lua
Last active December 19, 2015 04:28
Example of routes with Turbo.
local turbo = require("turbo")
local IndexHandler = class("IndexHandler", turbo.web.RequestHandler)
function IndexHandler:get()
self:write("Index..")
end
local UserHandler = class("UserHandler", turbo.web.RequestHandler)
function UserHandler:get(username)
self:write("Username is " .. username)
@enotodden
enotodden / turbo_static_example.lua
Last active December 19, 2015 04:28
Example of serving static files with Turbo.
local turbo = require "turbo"
application = turbo.web.Application:new({
{"/static/(.*)$", turbo.web.StaticFileHandler, "/var/www/"},
})
application:listen(8888)
turbo.ioloop.instance():start()
@enotodden
enotodden / turbo-virtual-env-example.sh
Last active December 19, 2015 17:49
turbo-virtual-env usage example
# Create a new environment with turbo-virtual-env, with the 'penlight' package from luarocks.
$ cd /tmp
$ mkdir myproject
$ cd myproject
$ #Tell turbo-virtual-env to pass 'penlight' to luarocks for installation
$ echo "penlight" >> ./requirements.txt
$ turbo-virtual-env --create ./env -r ./requirements.txt
@enotodden
enotodden / .cdsmap.example
Created July 18, 2023 09:21
cds - cd with aliases
# This is a comment, only seperate-line comments are supported
mything /long/path/to/my/thing
foo /Users/myuser/bar
# When a path doesn't start with / it is mapped relative to $HOME:
myotherthing Downloads/foo/bar