Skip to content

Instantly share code, notes, and snippets.

View stevedonovan's full-sized avatar

Steve J Donovan stevedonovan

View GitHub Profile
@stevedonovan
stevedonovan / SciteUser.properties
Created September 2, 2013 06:59
SciTE User properties for working with Nimrod
tabsize=4
indent.size=4
use.tabs=0
split.vertical=0
open.dialog.in.file.directory=1
statusbar.visible=1
# treat Nimrod like Python
file.patterns.nim=*.nim
lexer.$(file.patterns.nim)=python
import strutils
from os import ParamCount, ParamStr
import tables
export tables.`[]`
#### Simple string lexer ###
type
PLexer = ref TLexer
TLexer = object
str: string
@stevedonovan
stevedonovan / head.nim
Created September 2, 2013 06:44
A simple implementation of `head` in Nimrod
import parseopt
from strutils import parseInt
from os import existsFile
const usage = """
head [flags] filename
-n: number of lines (default 10)
-h,--help: this help
-v,--version: version
"""
@stevedonovan
stevedonovan / List.moon
Created August 10, 2013 12:35
A Moonscript class, documentation by LDoc,
----
-- A list class that wraps a table
-- @classmod List
import insert,concat,remove from table
class List
--- constructor passed a table `t`, which can be `nil`.
new: (t) =>
@ls = t or {}
@stevedonovan
stevedonovan / klass.moon
Created August 10, 2013 11:37
Alternative simple implementation of classes for Moonscript. This version is compatible with Lua classes created by Moonlight and Penlight.
ctor = (C,...) ->
obj = setmetatable {}, C
init = rawget C, '_init'
if init
init(obj,...)
return obj
is_class = (C) ->
mt = getmetatable C
if mt and C._class -- this is a base class!
@stevedonovan
stevedonovan / lint64.c
Last active May 18, 2016 06:44
An int64 module, for Lua 5.1/5,2, by Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br>, as extended by Steve Donovan (steve.j.donovan@gmail.com)
/*
* lint64.c
* int64 nummbers for Lua
* Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br>
* Thu Aug 1 22:56:17 BRT 2013
* This code is hereby placed in the public domain.
* Modified by Stevedonovan, Aug 3.
* __pow is defined by integer second arg
* new can be passed a hex literal string
* tohex will return a int64 as a hex string
@stevedonovan
stevedonovan / ld-parse.lua
Last active December 15, 2015 12:48
LuaDist batteries manifest; all modules which are directly installable. Third field is either 'no', 'yes' or <version> if there exists a higher version in the repo. A start made with annotating these entries with tags.
local f = io.open('info.txt')
local line = f:read()
local Q = '"'
local QC = '",'
--local tags = dofile 'tags.lua'
@stevedonovan
stevedonovan / form.moon
Created January 29, 2013 12:14
Simple Android Activity in MoonScript using AndroLua
require 'android'
require 'android.intents' -- needed for creating an email..
feedback_email = 'appfeedback@yourappsite.com'
_M = android.new!
with _M
-- compare to this more standard implementation:
--http://mobile.tutsplus.com/tutorials/android/android-sdk-creating-forms/
@stevedonovan
stevedonovan / globalsplus.lua
Last active December 11, 2015 12:48
An extended undefined variable checker for Lua 5.1 using bytecode analysis based on David Manura's globalplus.lua http://lua-users.org/wiki/DetectingUndefinedVariables
-- globalsplus.lua
-- Like globals.lua in Lua 5.1.4 -- globalsplus.lua
-- Like globals.lua in Lua 5.1.4 but records fields in global tables too.
-- Probably works but not well tested. Could be extended even further.
--
-- usage: lua globalsplus.lua example.lua
--
-- D.Manura, 2010-07, public domain
--
-- See http://lua-users.org/wiki/DetectingUndefinedVariables
@stevedonovan
stevedonovan / struct.lua
Created November 19, 2012 12:56
'Strict' Structs in Lua.
-- struct.lua
--- defining a struct constructor ---
local function ordered_map (t)
local fields,keys = {},{}
for i,item in ipairs(t) do
local key,value = next(item)
fields[key] = value
keys[i] = key
end