Skip to content

Instantly share code, notes, and snippets.

@inmatarian
inmatarian / lzw.lua
Created December 27, 2014 02:14
LZW Compression in Lua, rosetta-code style, also includes a 8-bit only mode for 7bit plain text strings.
local lzw = {}
local function enc_reset(dict, size)
for k, _ in pairs(dict) do dict[k] = nil end
for i = 0, size-1 do dict[string.char(i)] = i end
return dict
end
local function dec_reset(dict, size)
for k, _ in pairs(dict) do dict[k] = nil end
" Header ---------------------------------------------------------------------
filetype on
call pathogen#infect() " Load Scripts from .vim/bundle
call pathogen#helptags()
set nocompatible
" Basic Options --------------------------------------------------------------
filetype plugin indent on
syntax on
set encoding=utf-8
@inmatarian
inmatarian / HuePalSorted.gpl
Last active September 20, 2015 01:30
Generates a Gimp palette based on HSL color space with a fixed saturation level
GIMP Palette
Name: HuePalSorted
Columns: 5
#
53 11 11 H0 S66 L12
106 21 21 H0 S66 L25
159 32 32 H0 S66 L37
212 43 43 H0 S66 L50
223 96 96 H0 S66 L62
53 32 11 H30 S66 L12
@inmatarian
inmatarian / brainfuck.lua
Created July 28, 2012 19:15
Bored Saturday Afternoon Brainfuck Interpreter
#!/usr/bin/lua
-- Brainfuck Interpreter in Lua
-- A result of an hour of boredom on a saturday
--[[
Example: Hello World
++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.
@inmatarian
inmatarian / class.lua
Created October 2, 2012 21:51
A class library I'm evolving as needed.
--[[
--
-- Inny's Class Library
--
-- Instances use classes as metatables
-- Subclasses are copies of parent classes (vtable style)
-- All classes can be instantiated through Class() or Class:new()
-- Class declarations can include bodies: X = class { member = value }
-- Classes can declare metamethods for instances
-- __index and __newindex are handled through getattr and setattr
@inmatarian
inmatarian / stride.lua
Created January 4, 2014 19:26
Implementation of a Strided Array, a generalized data structure for accessing a single array through a multiple dimension view.
local stride, stride_accessor, TERMINATOR
stride = {
_VERSION = "stride.lua 1.0",
_DESCRIPTION = [[
Strided arrays are a generalized version of multi-dimensional arrays.
Use this instead of doing a lot of A[1+(y-1)*width+(x-1)] mayhem all over.
Example usage:
my_array = { 1, 2, 3, 4, 5, 6 }
view2d = stride.new(my_array, {3, 2})
@inmatarian
inmatarian / ascii.lua
Created April 19, 2015 21:14
vim autocomplete friendly enumeration of CP437 ascii characters
local ascii = {}
ascii.null = 0
ascii.empty_smiley = 1
ascii.smiley = 2
ascii.heart = 3
ascii.diamond = 4
ascii.club = 5
ascii.spade = 6
ascii.dot = 7
ascii.inverse_dot = 8
@inmatarian
inmatarian / optparse.lua
Created April 12, 2016 04:20
Minimal command line options parser (with tests)
-- Fast options parser
-- License: Public Domain
-- Can parse --arg=value types
-- Anything not --arg or --arg=value are positional types
-- Everything is a string, doesn't parse anything for you
-- OS/Host usually does the string split for you, so I don't bother.
-- Isn't POSIX compliant, because -arg and --arg and ---arg are treated the same.
function optparse(...)
local cfg = {}
@inmatarian
inmatarian / funky.lua
Last active June 13, 2016 23:38
latest version of funky.lua
-- Funky.lua, collection of functional tools
local _ENV = setmetatable({}, {__index = _ENV or _G})
if setfenv then setfenv(1, _ENV) end
unpack = unpack or table.unpack
local __ = {}
do
-- We need a fast way to check for placeholders. All funkier libraries
-- will need to register themselves as a funky placeholder.
@inmatarian
inmatarian / bf-fn.lua
Created October 7, 2016 01:28
brainfuck, recursive interpreter implementation, cuz why not.
function abs(x)
if x < 0 then
return -1
else
return 1
end
end
oper = {}