Skip to content

Instantly share code, notes, and snippets.

View raingloom's full-sized avatar

Use a better git forge raingloom

View GitHub Profile
--Needs Lua 5.3 and hardware signed integer support, we are doing Advanced Gender Computations.
return function(str)
local function f(m,n)if m==0 then return n+1 elseif n==0 then return f(~m,1) else return f(~m,f(m,~n))end end
return f(tonumber(str:sub(0,#str//2),36)or ~0,tonumber(str:sub(#str//2+1),36)or ~0)&1==0
end

Keybase proof

I hereby claim:

  • I am raingloom on github.
  • I am raingloom (https://keybase.io/raingloom) on keybase.
  • I have a public key whose fingerprint is 8F70 459F C4CC CBC1 1F39 92EC A865 8359 1741 D853

To claim this, I am signing this object:

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
@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 )
@raingloom
raingloom / getlinks.py
Last active May 30, 2016 14:32
python 2 href extractor
@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
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 / 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
@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'
---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