Skip to content

Instantly share code, notes, and snippets.

View jsuchal's full-sized avatar

Jano Suchal jsuchal

View GitHub Profile
@jsuchal
jsuchal / polyconf-raffle.rb
Created September 8, 2014 19:13
polyconf-raffle.rb
list = "Alban Leveau-Vallier
Wa Wa
Jan Gondol
Jozef Vaclavik
Igor Hlina
Ivka Drábiková
Pavol Bielik
Peter Dubec
Tibor Arpas
Michal Macejko
require 'rspec'
require 'nokogiri'
class Scraper < Struct.new(:downloader, :persistor)
def scrape(id)
html = downloader.download("http://www.statistics.sk/pls/wregis/detail?wxidorg=#{id}")
doc = Nokogiri::HTML(html)
subject = { original_id: id }
require 'rspec'
class CachedRepository
def initialize(repository)
@repository = repository
@cache = {}
end
def find(id)
unless @cache.include?(id)
class Number < Struct.new(:value)
def print
value
end
end
class Binary < Struct.new(:left, :right)
end
class Plus < Binary
require 'minitest/autorun'
ARABIC_VALUES = {
'I' => 1, 'V' => 5, 'X' => 10, 'L' => 50, 'C' => 100, 'D' => 500, 'M' => 1000
}
def from_roman(roman)
chars = roman.chars << 'I'
chars.each_cons(2).inject(0) do |sum, (c1, c2)|
sum + (ARABIC_VALUES[c1] < ARABIC_VALUES[c2] ? -ARABIC_VALUES[c1] : ARABIC_VALUES[c1])
require 'minitest/autorun'
@jsuchal
jsuchal / example.rb
Last active August 29, 2015 14:00 — forked from franckverrot/example.rb
class InviteController < ApplicationController
# The controller's responsibility is to build an object graph
# that will do the hard work.
def accept
scenario = InvitationScenario.new
scenario.accept_invite_token_for_user(current_user, params[:token], bus.when(
inviting_succeeded: ->(user) { redirect_to invite.item, notice: "Welcome!" },
inviting_failed: ->(error) { redirect_to '/', alert: "Oopsy!" }
))
def link_to_notifiable(notifiable)
notifiable.link_to_notifiable(self)
end
# concerns/notifiable_presenters.rb
class Answer
def link_to_notifiable(helper)
helper.link_to_answer, question
end
end
# sandi
module GildedRose
DEFAULT_CLASS = Item
SPECIALIZED_CLASSES = {
'normal' => Normal,
'Aged Brie' => Brie,
'Backstage passes to ...' => Backstage
}
def self.for(name, quality, days_remaining)
class DonationsController # < ActionController::Base
def create
donation_service.add_donation(current_user, params, bus.on(
donation_created: ->(donation) { send_user_to_payment_gateway(donation) },
donation_invalid: ->(donation) { render donation.errors, status: :bad_request }
))
end
private
def donation_service