Skip to content

Instantly share code, notes, and snippets.

View stevedonovan's full-sized avatar

Steve J Donovan stevedonovan

View GitHub Profile
@stevedonovan
stevedonovan / mockup.ltp
Created October 11, 2012 05:59
Penlight-style Lua template for HTML with JavaScript; note @ used as escape!
<!DOCTYPE HTML>
<html>
<head>
<script src="/flot/jquery.min.js" type="text/javascript"></script>
<!--[if lte IE 8]><script language="javascript" type="text/javascript" src="/media/flot/excanvas.min.js"></script><![endif]-->
<script language="javascript" type="text/javascript" src="/flot/jquery.flot.min.js"></script>
<script language="javascript" type="text/javascript" src="/flot/jquery.flot.navigate.js"></script>
<style type="text/css">
.center { text-align:center; }
@stevedonovan
stevedonovan / ChartExample.java
Last active January 13, 2022 09:36
Android Example using AChartEngine to plot JSON data
package com.example.testchart;
import java.util.*;
import java.io.*;
import java.text.DateFormat;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.*;
@stevedonovan
stevedonovan / foo.c
Created May 25, 2012 10:07
A Lua script to embed Lua code in a C module.
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
#ifdef WIN32
#define EXPORT __declspec(dllexport)
#else
#define EXPORT
#endif
static const char * lua_code = \
@stevedonovan
stevedonovan / deb.lua
Created May 8, 2012 11:53
Correspondance between Lua modules and Debian packages (from ldeb)
local packages = {
bit="liblua5.1-bitop0", -- -- fast bit manipulation library for the Lua language v
cgilua="liblua5.1-cgi0", -- -- CGI library for the Lua language version 5.1
sapi="liblua5.1-cgi0", -- -- CGI library for the Lua language version 5.1
copas="liblua5.1-copas0", -- -- Copas is a dispatcher of concurrent TCP/IP requests
cosmo="liblua5.1-cosmo0", -- -- A template library for the Lua langua version 5.1
coxpcall="liblua5.1-coxpcall0", -- -- Protected function calls across coroutines for Lua 5
curl="liblua5.1-curl0", -- -- libcURL bindings for the Lua language version 5.1
luaevent="liblua5.1-event0", -- -- asynchronous event notification library for Lua vers
lxp="liblua5.1-expat0", -- -- libexpat bindings for the Lua language version 5.1
@stevedonovan
stevedonovan / array.lua
Created March 26, 2012 12:35
Covariance with pl.class: a specialized List of numbers
require 'pl'
class.Array(List)
function Array.__add (a1,a2)
return a1:map2('+',a2)
end
function Array.__sub (a1,a2)
return a1:map2('-',a2)
@stevedonovan
stevedonovan / ml.lua
Created February 15, 2012 09:36
Microlight - a really compact set of general Lua functions
-----------------
-- Microlight - a very compact Lua utilities module
--
-- Steve Donovan, 2012; License MIT
-- @module ml
local ml = {}
--- String utilties.
-- @section string
@stevedonovan
stevedonovan / list.moon
Created December 15, 2011 10:33
An example of a MoonScript class
import insert,concat,remove from table
class List
new: (t) =>
@ls = t or {}
add: (item) =>
insert @ls,item
@stevedonovan
stevedonovan / csvdta.go
Created December 2, 2011 08:06
A Go package which reads structure data from CSV data using reflection
package csvdata
// csvdata complements the csv package by allowing you to map a custom structure to
// the columns of data in a CSV file. The struct needs to be annotated so that each
// field can match a column in the data
//
// type Person struct {
// FirstName string `field:"First Name"`
// Second_Name string
// Age int
// }
@stevedonovan
stevedonovan / loader.lua
Created October 19, 2011 09:52
A Custom Lua module loader for Lua 5.2
-- This allows a more restricted module() style; the key feature
-- is that each module is loaded in a custom environment, and the actual module
-- table is a copy of that environment after initial load.
-- clone _G so that globals from the program don't invade the module
local lua_libs = {}
for k,v in pairs(package.loaded._G) do
lua_libs[k] = v
end
@stevedonovan
stevedonovan / html.lua
Created September 5, 2011 09:40
Orbit-style Htmlification using LuaExpatUtils
--[[
See http://steved-imaginaryreal.blogspot.com/2011/09/htmlification-with-lua.html
Example usage:
-- test2.lua
require 'html'
html {
body { title 'Test' },
h2 'title',
p 'first para',