Skip to content

Instantly share code, notes, and snippets.

@kikito
kikito / busted.md
Created February 6, 2016 23:02
What I would change about busted

What I would change about busted

This document describes my thoughts on busted. My opinion on the tool is an ever-evolving thing, so these are not set in stone. I am writing them here to encourage discussion, more than to convince anyone.

1. Remove the "automatic Lua detection logic"

(This might have been removed on latest busted versions)

busted does this thing where it "tries to be smart" and use the "most appropiate" version of Lua available on your system.

Process: love [50818]
Path: /Users/USER/Downloads/*/Wanderer.app/Contents/MacOS/love
Identifier: com.RedCloakGames.Wanderer
Version: ???
Code Type: X86-64 (Native)
Parent Process: ??? [1]
Responsible: love [50818]
User ID: 501
Date/Time: 2015-09-21 22:03:37.327 +0200
Kaminari.configure do |config|
# config.default_per_page = 25
# config.max_per_page = nil
# config.window = 4
# config.outer_window = 0
# config.left = 0
# config.right = 0
# config.page_method_name = :page
# config.param_name = :page
end
@kikito
kikito / with_block.rb
Created September 10, 2015 10:15
Comment length validation options
class Comment < ActiveRecord::Base
validate do
validator = ActiveModel::Validations::LengthValidator.new(
attributes: :body,
minimum: 10,
maximum: Comment.body_max_length)
validator.validate(self)
end
$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
default: The Berkshelf shelf is at "/Users/kikito/.berkshelf/vagrant-berkshelf/shelves/berkshelf20150731-16929-7x0hdo-default"
==> default: Sharing cookbooks with VM
==> default: Importing base box 'opscode_debian-8.1'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: participacion_default_1438338885807_45836
==> default: Updating Vagrant's Berkshelf...
==> default: Resolving cookbook dependencies...
==> default: Fetching 'participacion' from source at chef/participacion
[ {"id": 1, "name": "First class"}, {"id": 2, "name": "Second class"} ]
@kikito
kikito / assert_contains.lua
Created August 29, 2014 11:44
Lua Busted table contains assertion
local s = require("say")
local function contains(container, contained)
if container == contained then return true end
local t1,t2 = type(container), type(contained)
if t1 ~= t2 then return false end
if t1 == 'table' then
for k,v in pairs(contained) do
if not contains(container[k], v) then return false end
local spec = require 'spec'
local yo = require 'yo-api.yo'
describe("yo-api", function()
describe("when the uri is /", function()
it("sends an email and a notification", function()
local request = { method = 'GET', url = '/?username=peter' }
local expected_backend_request = { method = 'GET', url = '/?username=peter', headers = {['Content-Type'] = 'application/json'}}
local next_middleware = function(req, next_middleware)
assert.contains(req, expected_backend_request) -- new assertion
local spec = require 'spec'
local yo = require 'yo-api.yo'
describe("yo-api", function()
describe("when the uri is /", function()
it("sends an email and a notification", function()
local request = { method = 'GET', url = '/?username=peter' }
local expected_backend_request = { method = 'GET', url = '/?username=peter', headers = {['Content-Type'] = 'application/json'}}
local tester = spec.new(yo)
@kikito
kikito / grid.lua
Created May 29, 2014 12:48
Grid traversal
local grid = {}
local function grid_toCell(cellSize, x, y)
return math.floor(x / cellSize) + 1, math.floor(y / cellSize) + 1
end
-- grid_traverse* functions are based on "A Fast Voxel Traversal Algorithm for Ray Tracing",
-- by John Amanides and Andrew Woo - http://www.cse.yorku.ca/~amana/research/grid.pdf
-- It has been modified to include both cells when the ray "touches a grid corner",
-- and with a different exit condition