HELLO, I’M SERHAT AND THIS IS MY FANCY TITLE.

Boolean Type Words in YAML


YAML is a widely used data serialization language. In any software development project, or a random dev-ops task you can come across with YAML. For example Ruby on Rails uses YAML for fixtures, configuration files and localization. CI/CD tools such as CircleCI and Travis also use YAML for configuration. If you ever experienced a strange behaviour with YAML, you may have used the reserved words of YAML. YAML reserves some words such as 'yes', 'no', 'y', 'n', 'off', 'on', etc. for boolean type. For example:

yes:
    turkish: evet
    german: ja
    english: yes
no:
    turkish: hayır
    german: nein
    english: no

will be interpreted as:

true:
    turkish: evet
    english: true
false:
    turkish: hayır
    english: false
Read more
Date: 04-05-2018

Rails Instantiated Fixtures


Here we have sample Ruby on Rails fixture file:

test/fixtures/newsletters.yml

tenant_newsletter:
  name: sample
  text_message: hello
  phone_number: 0555444332211
  first_name: foo
  last_name: bar

There are two popular ways to use fixtures in your Rails tests. The first one is directly calling the name of fixture file followed by a symbol stating the name of any individual fixture, ie:

class NewsletterTest < ActiveSupport::TestCase
  test 'a sample test' do
    assert newsletters(:tenant_newsletter).valid?
  end
 end
Read more

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.

Read more

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"
end

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.

Read more

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.

Read more