This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[ | |
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
---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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local free, free_l = {}, 0 | |
local _print = print | |
local function dealloc( t ) | |
free_l = free_l + 1 | |
free[ free_l ] = t | |
return true | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import html5lib | |
def filterHref( stream ): | |
return filter( lambda x: x.get("href") is not None, html5lib.html5parser.HTMLParser().parse( stream ).iter()) | |
if __name__ == '__main__': | |
import sys | |
import io | |
for e in filterHref( io.open( sys.argv[1], mode="r" )): | |
print( e.get("href") ) #because Python 3 is better, but 2 is smart enough not to mess up one-element tuples |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
OlderNewer