Skip to content

Instantly share code, notes, and snippets.

View jsuchal's full-sized avatar

Jano Suchal jsuchal

View GitHub Profile
class SRPViolationError < StandardError
def initialize(klass)
@klass = klass
end
def message
"Class #{@klass} surely does something AND detects SRP violation, right? Well, your class should do only one thing! :D"
end
end
{
"indices":{
"crowdcloud_production":{
"index":{
"primary_size":"22.5gb",
"primary_size_in_bytes":24211211120,
"size":"22.5gb",
"size_in_bytes":24211211120
},
"translog":{
bus = On::Bus.new.
subscribe(DonationReceipt).
subscribe(NotifyAccountingSystem).
subscribe(UpdatePublicStats).
subscribe(LogInternalMetrics).
subscribe(UpdateAnalyticsDashboard).
subscribe(RealtimeViewerUpdate)
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
# sandi
module GildedRose
DEFAULT_CLASS = Item
SPECIALIZED_CLASSES = {
'normal' => Normal,
'Aged Brie' => Brie,
'Backstage passes to ...' => Backstage
}
def self.for(name, quality, days_remaining)
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
@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!" }
))
require 'minitest/autorun'
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])
class Number < Struct.new(:value)
def print
value
end
end
class Binary < Struct.new(:left, :right)
end
class Plus < Binary