Find the Real Names of Telegram Users Just with a Phone Number

I follow and admire Telegram project since their first release. If you haven't already heard about Telegram, it is a messaging platform with tons of useful privacy and security features, and offered completely for free. Telegram project still misses some key features such as an open source codebase and organization level Github repository, to gain my full adoption, but I trust their guarantee for making the source code open in the future.

Yesterday I noticed an interesting behavior of Telegram, and perhaps a potential issue to concern about your privacy. During an update on my contact list, I accidentally noticed that I could retrieve the real names of random people just with mobile numbers.

TL;DR: If you ever created a Telegram account with your real name, anyone with your phone number can reveal it. Or anyone generating a random list of phone numbers can match which phone number belongs to whom. In reverse, you can find the real names of prank callers, or just random people.

Continue reading

Running Shell Commands with Rake

We all owe to Jim Weirich (RIP) - the father of the Rake, developer of many great projects such as builder, RubyKoans (I also contributed to this project lately with some PRs) and Git Immersion. I learned a lot from his talks on YouTube and really admire him.

In this post, I'm going to share a small tip about Rake for his memory and his awesome work.

Running shell commands with Rake is actually pretty simple and straightforward. sh followed by some bash commands is what we are going to be using.

Here is a basic example:

task :gs do
  sh "git status"

After defining the task like shown above, just run the task with:

$ rake gs

and you will see exactly the same output as git status does.

Continue reading
Date: | Tags: rake, ruby and rake, rake examples, shell commands with rake | Categories: tech, ruby

Max Common Array Slice with Ruby

Question: We need a program which takes a comma delimited array of numbers from STDIN and will output the maximum slice of the array which contains no more than two different numbers. Your result should be written to STDOUT.

Example 1:

[1, 1, 1, 2, 2, 2, 1, 1, 2, 2, 6, 2, 1, 8] = 10 because the array slice of (0, 9) is the largest slice of the array with no more than two different numbers.

Example 2:

[53, 800, 0, 0, 0, 356, 8988, 1, 1] = 4 because the slice of (1, 4) is the largest slice of the array with no more than two different numbers. The slice (2, 5) would also be valid and would still give a result of 4.

'Max common array slice' (also known as Maximum sub-array problem) is a classical programming test question requiring some knowledge of O(n2) or O(n3). It is often asked in technical interviews in two different ways; a) maximum sum of array elements with no more than two different numbers, b) maximum length of array elements with no more than two different numbers. You can see more about Max Common Array Slice on Codility and Wikipedia.

Continue reading
Date: | Tags: max common array slice, longest array slice ruby, array slice ruby | Categories: tech, ruby

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')
Continue reading

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.

Continue reading