Skip to content

Instantly share code, notes, and snippets.

View raingloom's full-sized avatar

Use a better git forge raingloom

View GitHub Profile
--Based on Lua JiT's example code and the vector-light library from HardonCollider
local ffi=require"ffi"
ffi.cdef[[
typedef struct vector2 { double x, y ;} vector2_t;
]]
local vector2
@raingloom
raingloom / ProFi.lua
Last active August 29, 2015 14:25 — forked from perky/ProFi.lua
ProFi, a simple lua profiler that works with LuaJIT and prints a pretty report file in columns.
--[[
ProFi v1.3, by Luke Perkin 2012. MIT Licence http://www.opensource.org/licenses/mit-license.php.
Example:
ProFi = require 'ProFi'
ProFi:start()
some_function()
another_function()
coroutine.resume( some_coroutine )
ProFi:stop()
---easily pluggable into any part of code for a quick insight
-- example: local x = math.sin ( 123 )
-- local x = debug.print ( math.sin ( 123 ) )
-- prints all passed arguments as strings and returns them as-is
function debug.print ( ... )
print ( ... )
return ...
end
@raingloom
raingloom / here.lua
Created November 25, 2015 17:46
path up until current module (usually the current directory)
local prefix = ... and (...):match '(.-%.?)[^%.]+$' or ''
print( prefix )
--preserves last dot
--possible improvement: get module separator from package.config, usually not needed
--[[examples
require 'module.submodule'
module.
require 'long.path.to.submodule'
long.path.to.
dofile 'module.lua'
@raingloom
raingloom / rip.lua
Last active December 8, 2015 23:53
Multi-disk audio CD ripper script using VLC
--Rips an audio cd using VLC
--Tested on Arch Linux, may or may not work on other Unix systems
local outdir="out/Welcome-to-Night-Vale/Book"
local fout=outdir.."/Chapter-%04d.mp3"
local sessionLimit=math.huge
os.execute( "mkdir -vp "..outdir )
local dev="/dev/cdrom"
local offset=0
local sqrt, sin, cos = math.sqrt, math.sin, math.cos
local pi = math.pi
local r1, r2 = 0 , 1.0
local g1, g2 = -sqrt( 3 )/2, -0.5
local b1, b2 = sqrt( 3 )/2, -0.5
--[[--
@param h a real number between 0 and 2*pi
@param s a real number between 0 and 1
@raingloom
raingloom / init.lua
Created May 5, 2016 21:34
table allocation management for Lua
local free, free_l = {}, 0
local _print = print
local function dealloc( t )
free_l = free_l + 1
free[ free_l ] = t
return true
end
@raingloom
raingloom / getlinks.py
Last active May 30, 2016 14:32
python 2 href extractor
@raingloom
raingloom / pairs.lua
Last active August 18, 2016 17:47
Mobdebug metamethod tests
local evilmt = { "somevalue" }
---[[
function evilmt:__pairs()
return pairs{"Wrong table :P"}--the output is not what I expected but it is also not correct
--return next,self--for normal output
end--]]
setmetatable( evilmt, evilmt )
local src = package.searchpath( (...):gsub( '(%.)(.-)$', '%1_%2' ), package.path )
--used in Module.lua to find _Module.lua
--used for when the source needs source transformation