Skip to content

Instantly share code, notes, and snippets.

View nepalez's full-sized avatar

Andrew Kozin nepalez

  • Evil Martians
  • Lisbon, Portugal
View GitHub Profile
@nepalez
nepalez / ruby_challenges.rb
Last active August 29, 2015 14:25
ruby challenges
# identity
id = -> v { v }
# composition
composition = -> g, f { -> v { g[f[v]] } }
# testing for id
g = -> v { v * 2 }
composition(g, id)[3] == g[3] # true
composition(id, g)[3] == g[3] # true
require 'equalizer'
module Checkproc
InvalidValueError = Class.new(StandardError) { include Equalizer.new(:message) }
class Composite
attr_reader :left
attr_reader :right
def initialize(left, right)
@nepalez
nepalez / jruby
Last active August 29, 2015 14:24 — forked from d4rky-pl/meth_vs_proc.rb
Calculating -------------------------------------
method 56.995k i/100ms
proc 49.213k i/100ms
proc new 57.562k i/100ms
-------------------------------------------------
method 1.797M (±10.7%) i/s - 8.891M
proc 1.522M (± 8.3%) i/s - 7.579M
proc new 1.867M (± 7.9%) i/s - 9.267M
Comparison:
@nepalez
nepalez / gist:3f48353a206eaa244165
Created May 21, 2015 22:56
ROM commands chaining with mapper
require "rom"
ROM.setup :memory
class Users < ROM::Relation[:memory]
register_as :users
end
class Tasks < ROM::Relation[:memory]
register_as :tasks
end
@nepalez
nepalez / test
Created October 25, 2014 16:58
json-schema test
require 'json-schema'
text = '{"uuid":"3ea8fd89-232f-4ed1-90b5-743da173cd7d","name":"FIRM"}'
schema = '
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",