Skip to content

Instantly share code, notes, and snippets.

@JustAPerson
JustAPerson / class.lua
Created January 30, 2012 03:38
custom class system
local type = type;
local function deepcopy(obj)
local new = {};
local type, constant = type, "table";
for i,v in pairs(obj) do
if type(v) == constant then -- if type == "table"
new[i] = deepcopy(v);
else
new[i] = v;
function copy(t)
local type, const = type, "table";
local new = {};
for i, v in next, t do
if type(v) == const then
new[i] = copy(v);
else
new[i] = v;
end
end
@JustAPerson
JustAPerson / args.lua
Created April 4, 2012 22:12 — forked from SunsetTech/args.lua
Number of arguments in function -- Extended with number of upvalues
function int(t)
return t:byte(1)+t:byte(2)*0x100+t:byte(3)*0x10000+t:byte(4)*0x1000000
end
function num_args(func)
local ok, dump = pcall(string.dump,func)
if (not ok) then return -1 end
local cursor = 13
local offset = int(dump:sub(cursor))
cursor = cursor + offset + 13
@JustAPerson
JustAPerson / gist:2898929
Created June 9, 2012 01:01
Badcode: A child's attempt at a SHA256 hash implementation and a cipher inspired by AES.
--[[
the Advanced Roblox CryptoSystem, or ARCS, is being designed to bring better security to roblox games, such as private servers.
While still in its infancy, hopefully one day, ARCS will become a suitable means of data encryption.
ARCS currently supplies 2 features.
A secure Hash function,
And secure encryption algorithm.
@JustAPerson
JustAPerson / bxor.lua
Created July 13, 2012 03:40
Insanely fast XOR routine in Lua. (0.6 microsecond calls)
-- Original Author: http://www.roblox.com/Crypt-item?id=40531920
-- A readable mirror: http://roblox-asset.comoj.com/40531920
--
-- I have modified the final bxor() declaration at the bottom
-- for optimization (CSE via local k1, k2, k3, k4)
local ins=table.insert
local mf=math.floor
local bxor=function(a,b)
@JustAPerson
JustAPerson / debugger2.lua
Created September 19, 2012 02:58
Debugger attempt for Textadept
-- ~/.textadept/modules/lua/debugger2.lua
-- My derived work, based on ~/.textadept/modules/lua/debugger.lua
require 'textadept.debugger'
local mobdebug = require 'lua.mobdebug'
local handle = mobdebug.handle;
local debugger = _M.textadept.debugger.new('lua');
_M.lua.debugger = debugger;
import Data.Numbers.Primes
p007 n = last $ take n $ filter isPrime [1..]
main = print $ p007 10001
@JustAPerson
JustAPerson / .vimrc
Created August 24, 2013 02:50
So basic
set nocompatible " be iMproved
filetype off " required!
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
" let Vundle manage Vundle
" required!
Bundle 'gmarik/vundle'
Bundle 'leafo/moonscript-vim'
@JustAPerson
JustAPerson / test.rs
Created January 21, 2014 01:58
How to reference from index operator?
struct Buffer<T> {
list: ~[Option<T>],
size: uint,
}
impl<T: Clone> Buffer<T> {
pub fn new(size: uint) -> Buffer<T> {
let mut list: ~[Option<T>] = ~[];
list.reserve(size);
Buffer {
list: list,
extern crate regexp;
static VARIANTS : [&'static str, ..9 ] = [
"agggtaaa|tttaccct",
"[cgt]gggtaaa|tttaccc[acg]",
"a[act]ggtaaa|tttacc[agt]t",
"ag[act]gtaaa|tttac[agt]ct",
"agg[act]taaa|ttta[agt]cct",
"aggg[acg]aaa|ttt[cgt]ccct",
"agggt[cgt]aa|tt[acg]accct",