Skip to content

Instantly share code, notes, and snippets.

View oinak's full-sized avatar

Fernando Martínez oinak

View GitHub Profile
@oinak
oinak / clave.rb
Created October 5, 2017 09:57
XKCD approved password generator (https://www.xkcd.com/936/)
# https://www.xkcd.com/936/
module Clave
extend self
def run
puts((1..4).map { safe_words.sample }.join(" "))
end
private
@oinak
oinak / env_vars.rb
Last active September 27, 2017 15:08
Passing ENV vars from bash to ruby
# env_vars.rb
puts "A:#{ENV["AAA"]}"
puts "B:#{ENV["BBB"]}"
puts "C:#{ENV["CCC"]}"
puts "D:#{ENV["DDD"]}"
@oinak
oinak / iban_fix.rb
Created September 13, 2017 10:20
Read info from iban_registry.txt
# countries on sepa
sepa = %w(AT BE BG CH CY CZ DE DK EE ES FI FR GB GR HR HU IE IS IT LI LT LU LV
MC MT NL NO PL PT RO SE SI SK SM)
# config file from iso-iban gem
file = File.read(File.join('data','iso-iban', 'specs.yaml'))
config = YAML.load(file)
# sepa countries with missing branch positions
missing = config.select do |code, values|
@oinak
oinak / .bash_aliases
Last active September 22, 2017 13:32
alias dk=docker
alias dc=docker-compose
alias dra='dc run app'
alias drabe='dc run app bundle exec'
alias drake='dc run app bundle exec rake'
alias drails='dc run app bundle exec rails'
# alias dea='docker-compose exec app'
alias deabe='dea bundle exec'
@oinak
oinak / .bash_aliases
Created February 6, 2017 09:44 — forked from ro-fdm/.bash_aliases
Git desde inicio en nueva maquina
alias bash='bash --login'
alias ls='ls --color'
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
alias t='tailf'
alias c='ccze -A'
alias ag='ack-grep'
alias g='git'
alias e='gvim '
@oinak
oinak / fib.c
Last active November 13, 2016 12:23
Basic performance comparison ruby/mruby (interpreted, mrb bytecode, c bytecode) with fibonacci(40)
#include <stdint.h>
const uint8_t fib_symbol[] = {
0x52,0x49,0x54,0x45,0x30,0x30,0x30,0x32,0xb2,0xe1,0x00,0x00,0x01,0x52,0x4d,0x41,
0x54,0x5a,0x30,0x30,0x30,0x30,0x49,0x52,0x45,0x50,0x00,0x00,0x01,0x34,0x30,0x30,
0x30,0x30,0x00,0x00,0x00,0xbb,0x00,0x03,0x00,0x07,0x00,0x01,0x00,0x00,0x00,0x1a,
0x01,0x80,0x00,0x48,0x02,0x00,0x00,0xc0,0x01,0x80,0x00,0x46,0x01,0x80,0x00,0x91,
0x01,0x80,0x80,0x20,0x00,0x80,0xc0,0x01,0x01,0x80,0x00,0x06,0x02,0x00,0x00,0x3d,
0x02,0x80,0x00,0x06,0x03,0x40,0x13,0x83,0x02,0x80,0x00,0xa0,0x02,0x01,0x40,0x3e,
0x01,0x80,0xc0,0xa0,0x01,0x80,0x00,0x91,0x01,0x80,0x80,0x20,0x02,0x00,0x40,0x01,
0x01,0x81,0x00,0xae,0x01,0x00,0xc0,0x01,0x01,0x80,0x00,0x06,0x02,0x00,0x01,0x3d,
@oinak
oinak / json_file_cache.rb
Created November 3, 2016 20:53
A meditation on service caches, with an example stroage class
require 'securerandom'
class JsonFileCache
def initialize(path = nil)
@path = path || "/tmp/cache/#{SecureRandom.uuid}" # safe default
end
# Retrieves whole cache or single record if key is provided
def get(key = nil)
@cache ||= load_file
# to be called:
# ExampleService[1, {some: 'opt'}]
class ExampleService < Services::Base
# customize your setup
def initialize(concrete, arguments = {})
@concrete = concrete
@arguments = arguments
end
# customize your processing
@oinak
oinak / bottles.rb
Created July 21, 2016 19:38
First go at 99 bottles of OOP exercise, following instructions, (code just for the green), running time: 21'
class Bottles
def song
verses(99, 0)
end
def verse(n)
<<-END
#{bottles(n).capitalize} on the wall, #{bottles(n)}.
#{what_now(n)}, #{bottles(n-1)} on the wall.
@oinak
oinak / Gemfile
Created June 15, 2016 15:34
Dummy backend for credit card form UI/UX exercise
source 'https://rubygems.org'
ruby '2.3.0'
gem 'sinatra'