Skip to content

Instantly share code, notes, and snippets.

View anonyo's full-sized avatar

Anonyo Hossain anonyo

View GitHub Profile
@anonyo
anonyo / rpn_calculator.rb
Created April 21, 2014 18:39
rpn_calculator
class RPNCalculator
attr_accessor :calculator
def initialize
@calculator = []
end
def push(x)
@calculator << x
end
@anonyo
anonyo / gist:61a0a2dd2923a5fde0cc
Last active August 29, 2015 14:23
Removing class argument dependency
class Gear
  attr_reader :chainring, :cog, :wheel 
  
  def initialize(chainring, cog, wheel)
    @chainring = chainring
    @cog       = cog
    @wheel     = wheel
  end
...
@anonyo
anonyo / plain_model.rb
Created April 20, 2016 20:42
Plain Ruby class that's meant to behave like ActiveRecord model without database persistence.
class PlainModel
include ActiveModel::Model
include ActiveSupport::Callbacks
include ActiveModel::Validations::Callbacks
define_callbacks :save
def save
if valid?
@anonyo
anonyo / benchmark.rb
Created August 22, 2016 20:55
Benchmarking hourly sidetiq
$: << File.dirname(__FILE__)+'/../lib'
require 'ice_cube'
require 'benchmark'
include IceCube
schedule = Schedule.new(now = Time.utc(2010, 1, 1)) do |s|
s.add_recurrence_rule(Rule.hourly(2))
end