Comparing Ruby Objects (Class Instances) and Equity in Ruby

Recently I needed to compare two different Ruby objects (or Class instances) in a project. I just Googled around a little bit, but found no clue. Then I just continued looking around and came across with a great article written by Alan Skorkin (Skorks).

Here is my sample Money::Cash class that I'm going to be using during this article:

module Money
  class Cash
    attr_accessor :amount, :currency

    def initialize(amount, currency)
      @amount = amount.round(2)
      @currency = currency.upcase

    def convert_to(rate)
      rate = rate.upcase
      current_rate = Money::Rate.all.find { |r| r.code == @currency }

      if current_rate.nil?
        raise TypeError, "#{rate} has not defined for Money::Cash object yet."
      elsif rate == @currency
        return self
        rate_value = current_rate.rates[rate.to_sym]
        return Money::Cash.new(amount * rate_value, rate)

As you might guess, there are two different classes in this project, Cash and Rate. Rate is holding exchange rates for the Cash object, and Cash is holding the amount and the currency of the money. I just followed some basic OOP principles. We already have a convert_to method available for money conversation which makes money conversations based on defined Rates. Let's create some new Cash instances first:

dollar = Money::Cash.new(50, 'USD')
euro = Money::Cash.new(10, 'EUR')
Read more

Markdown preview extension for sublime text 3

If you want to add markdown support to your Sublime Text, you can simply install some plug-ins. To do this, you must install the Package Control first. Then we will install Markdown Preview and Markdown Editing packages.

Read more

Untrack files in git

When you do some local changes on your code, but wish to untrack them in Git you can use --assume-unchanged flag.

This will tell git you want to start ignoring the changes to the file:

git update-index --assume-unchanged path/to/file

Read more
Date: 04-05-2017

Import huge databases faster in mysql

Recently I needed to import very huge SQL dumps to my local machine. There were 10 different .sql files dumped from Moodle and each of them were sized more than 10GB with approximately 5 million rows. First of all, I tried to import them in a traditional way by using:

mysql -u username -p some_db < database1.sql

However each import request took a very long time, approximately 6-7 hours for each .SQL file. Please also you consider that I conducted this operation in a brand new laptop with Intel i7 CPU, 16GB RAM and 512GB SSD disk. Since I didn't have 60 hours for importing all these dump files, I took a look for potential solutions and found a very effective one.

Read more

GEM - Pundit ile authorization (cancan alternatifi)

Ryan Bates'in sırra kadem basmadan önce geliştirdiği GEM'lerden biri de cancan. Ryan ortadan kaybolup cancan'i yetim bırakınca Bryan Rite önderliğinde bir grup geliştirici başka bir proje olan cancancan'i sahiplendi ve bunu geliştirmeye devam etti.

Yani cancancan sanılanın aksine cancan'den sonra ortaya çıkmış veya cancan'in yokluğuna karşılık geliştirilmiş bir GEM değil, 2009'dan beri hayatta olan bir proje. Ancak en aktif geliştirme sürecini ise 2014'ün Ocak ve Eylül ayları arasında (Ryan'ın ortadan kayboluşu) yaşıyor. Ryan nerede birileri tartışadursun, biz ayakları yere daha sağlam bakan alternatiflere gidelim.

Read more