Skip to content

Instantly share code, notes, and snippets.

View Yonaba's full-sized avatar
💭
I may be slow to respond.

Roland Yonaba

💭
I may be slow to respond.
View GitHub Profile
@randrews
randrews / facts.lua
Created April 1, 2011 05:46
Make Lua look like Prolog!
----------------------------------------------------------------------------------------------------
--- Making Lua look like Prolog:
---
--- Let's use metatables for something other than emulating prototype-based OO. By making the
--- __index metamethod create values for undefined things, we can make Lua look like Prolog!
--- We create empty tables for anything starting with a capital letter, functions that populate
--- those tables for lowercase things (to assign relationships) and if a name begins with "is_"
--- then it becomes a function that queries those tables.
----------------------------------------------------------------------------------------------------
@Yonaba
Yonaba / sor2.lua
Created June 29, 2011 16:20
Successive Over Relaxation (SOR) Algorithm : 2nd Approach
-- SOR Algorithm Implemented through Lua
function Norm(m)
local n = 0
for i,v in ipairs(m) do
n = n + v^2
end
return math.sqrt(n)
end
@perky
perky / ProFi.lua
Created May 30, 2012 20:32
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()
@Yonaba
Yonaba / Jumper_Stress_Test.lua
Last active December 11, 2015 21:48
A stress test for the pathfinding library Jumper (v1.8.1)
-- A stress test for the pathfinding library Jumper (v1.8.1)
-- Source: https://github.com/Yonaba/Jumper/tree/jumper-1.8.1-1
-- The purpose of this is to compare the relative performance of different
-- search algorithms implemented in Jumper. Time measurements uses Lua's
-- native os.clock with (milliseconds precision).
-- Library setup
local Grid = require 'jumper.grid'
@bellbind
bellbind / astar.js
Last active February 3, 2018 14:34
[nodejs][javascript]A* with Jump Point Search
// A* with Jump Point Search on JavaScript
// - python A*: https://gist.github.com/bellbind/147645
// utility: Priority Queue
var PQ = function PQ() {
return Object.create(PQ.prototype, {
array: {value: []},
});
};
PQ.prototype.empty = function () {
@markandgo
markandgo / class.lua
Last active December 18, 2015 06:09
A class system with a novel constructor
-- simple class
-------------------------------------------------
local mixin_reserved = {
['new'] = true,
['onMixin'] = true,
['__type'] = true,
['__index'] = true,
}
local base = {__type = 'Object'}
--# Main
-- A stress test for the pathfinding library Jumper
-- https://github.com/Yonaba/Jumper/tree/jumper-1.8.1-1
-- The purpose of this is to compare the relative performance of the different
-- search algorithms implemented in Jumper
-- Time measurements uses Lua's native os.clock with milliseconds precision
function setup()
local Grid = grid()
@tylerneylon
tylerneylon / learn.lua
Last active July 25, 2024 19:50
Learn Lua quickly with this short yet comprehensive and friendly script. It's written as both an introduction and a quick reference. It's also a valid Lua script so you can verify that the code does what it says, and learn more by modifying and running this script in your Lua interpreter.
-- Two dashes start a one-line comment.
--[[
Adding two ['s and ]'s makes it a
multi-line comment.
--]]
----------------------------------------------------
-- 1. Variables and flow control.
----------------------------------------------------
@riidom
riidom / user.lua
Last active April 10, 2017 07:12
ZBS config file "user.lua"
--[[--
Use this file to specify System preferences.
Review [examples](+C:\Dokumente und Einstellungen\dr\Desktop\ZeroBraneStudioEduPack-0.38-win32\cfg\user-sample.lua) or check [online documentation](http://studio.zerobrane.com/documentation.html) for details.
--]]--
local G = ...
styles = G.loadfile('cfg/tomorrow.lua')('Zenburn') -- theme
@Yonaba
Yonaba / subvsmatch.lua
Last active December 22, 2015 23:39
string.gmatch vs string.sub
-- Calls f(...) n-times
local function time(nm,times, f,...)
local st = os.clock()
for i = 1, times do
f(...)
end
local et = os.clock()
print(('(%s): Times (%d): %.2f ms')
:format(nm, times, (et-st)*1000))
end