Skip to content

Instantly share code, notes, and snippets.

View stevedonovan's full-sized avatar

Steve J Donovan stevedonovan

View GitHub Profile
@stevedonovan
stevedonovan / css.lua
Created August 30, 2011 10:31
A little Lua DSL for generating CSS
--[[
A Lua module that defines a little DSL for generating CSS
-- csstest.lua
require 'css'
width = 500
lmargin = 50
leftm = 150
gap = 10
@stevedonovan
stevedonovan / shared.rs
Created April 14, 2017 13:49
An ergonomic way of saying Rc<RefCell>
use std::rc::Rc;
use std::cell::{RefCell,Ref, RefMut};
use std::ops::Deref;
use std::fmt;
#[derive(Clone)]
struct Shared<T> {
v: Rc<RefCell<T>>
}
@stevedonovan
stevedonovan / prettify.lua
Created August 11, 2011 13:11
Script to convert Markdown source with code blocks into syntax-highlighted HTML.
-- translate Markdown with code blocks into HTML
-- with syntax highlighting.
-- If article.md was the source, Lua was the language and we
-- wanted a preview:
-- lua prettify.lua article lua preview
-- Without the last argument it will just write out the HTML body.
-- Languages supported are 'lua', 'cpp', 'java' and 'go
-- Indented code blocks may begin with an explicit @lang name line;
-- if you do this then mark every code block explicitly
-- e.g
@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 / 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 / install.lua
Created September 28, 2013 13:37
A simple Lua install script for Lua modules, extensions and scripts. Tested on Windows and Linux.
#!/usr/bin/env lua
--[[ -- installing LDoc
function install()
-- requires('pl','Penlight')
-- install_script 'ldoc'
end
--]]
-- --[[
@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 / 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 / el.lua
Created October 2, 2021 15:38
el is a Lua expression evaluator with shell-friendly shortcuts, like ^string and print[[]
#!/usr/bin/lua
-- Flatten ALL those tidy tables and add environment lookup
local tables = {math,io,os,string,bit32}
setmetatable(_G,{
__index = function(t,key)
for _,m in ipairs(tables) do
local v = m[key]
if v ~= nil then return v end
end
return os.getenv(key)
@stevedonovan
stevedonovan / common-rust-traits.md
Created July 1, 2018 12:38
The Common Rust Traits

What is a Trait?

In Rust, types containing data - structs, enums and any other 'aggregate' types like tuples and arrays - are dumb. They may have methods but that is just a convenience; they are just functions. Types have no relationship with each other.

Traits are the abstract mechanism for adding functionality to types and establishing relationships between them.