This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'rspec' | |
| class CachedRepository | |
| def initialize(repository) | |
| @repository = repository | |
| @cache = {} | |
| end | |
| def find(id) | |
| unless @cache.include?(id) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| list = "Alban Leveau-Vallier | |
| Wa Wa | |
| Jan Gondol | |
| Jozef Vaclavik | |
| Igor Hlina | |
| Ivka Drábiková | |
| Pavol Bielik | |
| Peter Dubec | |
| Tibor Arpas | |
| Michal Macejko |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Point < Struct.new(:x, :y) | |
| end | |
| # completely different file/project | |
| class Point | |
| def to_string | |
| "#{x}, #{y}" | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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}, |