Skip to content

Instantly share code, notes, and snippets.

View stevedonovan's full-sized avatar

Steve J Donovan stevedonovan

View GitHub Profile
@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 / 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 / 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
"""
import strutils
from os import ParamCount, ParamStr
import tables
export tables.`[]`
#### Simple string lexer ###
type
PLexer = ref TLexer
TLexer = object
str: string
@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
@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 / append-test.lua
Created November 27, 2013 13:12
Some experiments with new Lua table functions.
require 'tablex'
local M = tonumber(arg[1]) or 10000
local N = tonumber(arg[2]) or 1000
local t_msg, t_start
function start_t (msg)
t_msg = msg
t_start = os.clock()
!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/
!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/
!_TAG_PROGRAM_AUTHOR steve.j.donovan@gmail.com
!_TAG_PROGRAM_NAME ltags //
!_TAG_PROGRAM_URL http://github.com/stevedonovan/ltags /official site/
!_TAG_PROGRAM_VERSION 0.1 //
Q fs\win32.lua /^function Q(arg)$/;" m struct:luarocks.fs.win32
Q fs\lua.lua /^function Q(arg)$/;" m struct:luarocks.fs.lua
_ fs\lua.lua /^local _, ftp = pcall(require, "socket.ftp")$/;" v file:
absolute_name fs\win32.lua /^function absolute_name(pathname, relative_to)$/;" m struct:luarocks.fs.win32
@stevedonovan
stevedonovan / from.lua
Last active August 29, 2015 13:58
Utility module to simplify initializing locals from tables or modules.
local debug = require 'debug'
-- from.lua
-- supports some useful shortcuts when creating locals from tables or modules
-- require 'from'
-- local sin,cos,tan = slots(3) from(math)
-- local import,printf = slots(2) from 'pl.utils'
-- local pretty,utils,xml = slots(3) from 'pl.*'
--
-- Uses the debug library, so it's not very fast - only use for top-level initialization!
@stevedonovan
stevedonovan / CMakeLists.txt
Last active August 3, 2016 16:08
An extension module for Lily provding extra string functions.
include_directories("../src/")
add_library(xstr SHARED lily_xstr.c)
set_target_properties(
xstr
PROPERTIES
PREFIX ""
COMPILE_FLAGS "-fPIC -g"
)