Skip to content

Instantly share code, notes, and snippets.

View jsuchal's full-sized avatar

Jano Suchal jsuchal

View GitHub Profile
require 'rspec'
class CachedRepository
def initialize(repository)
@repository = repository
@cache = {}
end
def find(id)
unless @cache.include?(id)
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 }
@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
class Topic < ActiveRecord::Base
has_many :comments
has_one :last_comment, class_name: 'Comment'
end
class Comment < ActiveRecord::Base
belongs_to :topic
after_create :set_last_comment
#!/bin/bash
VERSION="1.1.1"
PORT="9333"
PWD=`pwd`
mkdir -p ~/elasticsearch/
cd ~/elasticsearch/
wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-${VERSION}.zip
def solve(a)
i = 0
last_error = 0
begin
i += 1
errors1 = [
2182449 - (a[0][0] + a[0][1] + a[0][2]),
893841 - (a[1][0] + a[1][1] + a[1][2]),
1307065 - (a[2][0] + a[2][1] + a[2][2])
Painting = Struct.new(:name, :year)
def first(list, sorter = nil)
list = list.sort(&sorter) if sorter
list.first
end
def rest(list, sorter = nil)
list = list.sort(&sorter) if sorter
_, *rest = list
class PaymentGatewayCallbackService
# New custom exception
TransactionFailed = Class.new(StandardError)
def callback(order_id, gateway_transaction_attributes)
order = Order.find(order_id)
transaction = order.order_transactions.create(callback: gateway_transaction_attributes)
# raise the exception when things went wrong
transaction.successful? or raise TransactionFailed
order.paid!
class Point < Struct.new(:x, :y)
end
# completely different file/project
class Point
def to_string
"#{x}, #{y}"
end
end
participants = {
'@ppidanic' => {shares: 0, likes: 0, statuses: 1},
'@honzajavorek' => {shares: 2, likes: 2, statuses: 2},
'@tylersiprova' => {shares: 7, likes: 10, statuses: 5},
'@jakub_lesko' => {shares: 0, likes: 0, statuses: 1},
'@ondrek' => {shares: 0, likes: 0, statuses: 1},
'@Puigcerber' => {shares: 4, likes: 7, statuses: 5},
'@OndroNR' => {shares: 0, likes: 0, statuses: 1},
'@martin_strycek' => {shares: 0, likes: 0, statuses: 2},
'@PredragToptal' => {shares: 0, likes: 0, statuses: 2},