Skip to content

Instantly share code, notes, and snippets.

@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
@kikito
kikito / tools.md
Last active March 19, 2018 21:39
Comparison of JS charting libraries for an Angular-based JS project

I got this list from wikipedia. Then I removed all the libraries that where not MIT, Apache or BSD and those with no sourcecode metrics (i.e. not on github, bitbucket, or trak). And then I added the columns I wanted.

Library Source Last Commit Last Closed Issue Stars Forks Ng-bindings Dependencies
ricksaw github 1 month ago 1 month ago 4309 685 Yes D3.js
nvd3 github 2 days ago 1 day ago 2433 814 Yes D3.js
Flot github 14 days ago 9 days ago 3349 842 Yes 1, [2](https://git
shared_state = {}
stack << MyCommand.new('dep1')
<< MyOtherCommand.new('dep2')
stack.call(shared_state, 'foo', 'bar', 'baz')
###
class MyCommand
@kikito
kikito / nginx.conf
Last active August 29, 2015 14:01
Test nginx infinite loops timeout
daemon off;
worker_processes 1;
events {
worker_connections 1024;
}
error_log /dev/stdout info;
http {
access_log /dev/stdout;