Skip to content

Instantly share code, notes, and snippets.

View RyanSquared's full-sized avatar

Ryan RyanSquared

View GitHub Profile
!(function(exports){var module;
var Module;if(typeof Module==="undefined")Module={};if(!Module.expectedDataFileDownloads){Module.expectedDataFileDownloads=0;Module.finishedDataFileDownloads=0}Module.expectedDataFileDownloads++;((function(){var loadPackage=(function(metadata){function runWithFS(){var fileData0=[];fileData0.push.apply(fileData0,[45,45,32,77,97,107,101,32,119,105,110,100,111,119,32,111,98,106,101,99,116,32,97,32,103,108,111,98,97,108,10,119,105,110,100,111,119,32,61,32,106,115,46,103,108,111,98,97,108,59,10,10,100,111,32,45,45,32,67,114,101,97,116,101,32,106,115,46,105,112,97,105,114,115,32,97,110,100,32,106,115,46,112,97,105,114,115,32,102,117,110,99,116,105,111,110,115,46,32,97,116,116,97,99,104,32,97,115,32,95,95,112,97,105,114,115,32,97,110,100,32,95,95,105,112,97,105,114,115,32,111,110,32,74,83,32,117,115,101,114,100,97,116,97,32,111,98,106,101,99,116,115,46,10,9,108,111,99,97,108,32,95,80,82,79,88,89,95,77,84,32,61,32,100,101,98,117,103,46,103,101,116,114,101,103,105,115,116,114,121,40,41,
@RyanSquared
RyanSquared / todo.md
Last active April 11, 2016 15:40
TODO list for The Neon Project
@RyanSquared
RyanSquared / characters.md
Created April 11, 2016 16:21
Characters for typing articles, etc.

Quotes

Left Double Tick: “

Right Double Tick: ”

Left Tick: ‘

Right Tick: ’

@RyanSquared
RyanSquared / bit.lua
Last active April 13, 2016 14:17
Functions "missing" from Lua standard library
local ok, bit = pcall(require, "bit")
if not ok and bit32 then
return bit32
elseif bit
return bit
else
local bit = {}
function bit.band(...)
local args = {...}
local bits
if [ "x$1" = "x" ]; then
echo "No file argument passed"
fi
dd if=/dev/zero of="$1"
rm "$1"
@RyanSquared
RyanSquared / README.md
Last active January 11, 2017 22:27
Lua OOP implementation

LuOOP

Quick and dirty OOP for Lua

Examples

Instance with class default value inheritance

local tClass = class({
 hello = "world";
@RyanSquared
RyanSquared / double-declining-balance.lua
Last active April 26, 2016 16:04
Double declining balance calculator
local function r(x) -- round to nearest even
local y = x * 100 -- shift decimal right
if math.floor(y) % 2 == 0 then -- even
return math.floor(y) / 100
else
return math.ceil(y) / 100
end
end
local function calculate(origin, salvage, usefullife)
local function straight_line(start, salvage, years)
local percentage = 1 / years
local to_decline = start-salvage
local depreciation = 0
for i=start, start-to_decline, -(to_decline) * percentage do
-- ignore first line
-- for some reason it doesn't work
print(start-depreciation, to_decline * percentage, start-i, i)
depreciation = depreciation + (to_decline * percentage)
end
rm -f /tmp/mirrorlist /tmp/mirrorlist.new || exit 1
sed "s/^#//" /etc/pacman.d/mirrorlist.pacnew > /tmp/mirrorlist
rankmirrors /tmp/mirrorlist > /tmp/mirrorlist.new
install -b /tmp/mirrorlist.new /etc/pacman.d/mirrorlist

Lua OOP Tutorial

Object-oriented programming in Lua is an often-debated topic and people normally assume that Lua, by default, has no way to implement object-oriented programming. However, obviously, there are multiple ways to implement object-oriented programming, which I will demonstrate in this article.

Method 1