Skip to content

Instantly share code, notes, and snippets.

-- transforms a pretty-but-difficult string into an ugly-but-easy array for tilemaps
local function string2Tiles(str)
local tiles = {}
local row_length = #(str:match("[^\n]+"))
for x = 1,row_length,1 do
tiles[x] = {}
end
require 'rubygems'
require 'rspec'
class Fixnum
ROMANS = { M: 1000, CM: 900, D: 500, CD: 400, C: 100, XC: 90, L: 50, XL: 40, X: 10, IX: 9, V: 5, IV: 4, I: 1 }
def to_roman
ROMANS.detect do |roman, arabic|
diff = self - arabic
return "#{roman}#{diff.to_roman}" if diff >= 0
end
@kikito
kikito / unnamed classes in Lua
Created April 18, 2011 07:30
automatically getting their name from _G
local function _getNameFromG(theClass)
for k,v in pairs(_G) do
if v == theClass then return k end
end
return "Anonymous" -- non-global classes will get "Anonymous"
end
function Object:subclass(name)
local theSubClass = {...}
...
@kikito
kikito / Foo.lua
Created April 26, 2011 08:01
Lua class implementation syntax example, using a DSL similar to Ruby
-- Option 1 "Conservative"
class("Foo", BaseClass, function(self)
def( "instanceMethod", function(self, param1, param2)
...
end)
self.def( "classMethod", function(self, param1, param2)
...
end)
@kikito
kikito / gist:960588
Created May 7, 2011 15:37
#coderetreat #valladolid iteration 7
context('ecomba', function()
context('adam', function()
adam = 1
test('God created Adam', function()
assert_not_nil(adam)
@kikito
kikito / gist:961442
Created May 8, 2011 15:40
tween demo (unfinished
tween = require 'tween'
function love.update(dt)
tween.update(dt)
end
local greenLight, yellowLight, redLight
@kikito
kikito / A.rb
Created August 18, 2011 12:20
Don't use self.methodname if methodname is private
class A
def foo
baz
end
def bar
self.baz
end
@kikito
kikito / config.ru
Created October 2, 2011 22:22
Minimal sinatra contact us app
require 'app'
# application-exclusive settings
set :smtp_port, '587'
set :smtp_server, 'smtp.gmail.com'
set :smtp_password, 'secret'
set :smtp_user, 'my_mail@example.com'
set :address, 'my_mail@example.com'
set :domain, 'example.com'
@kikito
kikito / life.lua
Created December 3, 2011 17:03
half-finished life in lua
local AliveCell = {}
function AliveCell:new(neighbors)
return setmetatable({neighbors = neighbors}, {__index = self})
end
function AliveCell:willLive()
return cell.neighbors > 1 and cell.neighbors < 4
end
@kikito
kikito / args_var_dump.php
Created December 13, 2011 12:37
wordpress / nav walker class / start_el function / $args (var dump)
object(stdClass)#134 (16) {
["menu"]=>
string(0) ""
["container"]=>
bool(false)
["container_class"]=>
string(0) ""
["container_id"]=>
string(0) ""
["menu_class"]=>