Igor Sarcevic

my path of programming enlightment

Read this first

Escape Sequences - A Quick Guide


Two year ago I thought I know a lot about the Linux command line. Then I started digging deeper. Replaced Bash with Zsh, learned about jobs, started writing shell scripts, and even ditched Sublime text in favor of editing with command line Vim. Again I thought I know a lot about the Linux command line. Then I started digging deeper again…

Few weeks ago I wrote a blog post that described how to create progress bars for command line application. There I have described how to stay on the same line, and thus simulate a filling progress bar. That blog post made me wonder if there is a way to change multiple lines of text at once. I started looking for a solution, but what I found was more amazing than I ever thought it would be.

The thing I have found was a way to insert escape characters in the output of your commands that would tell the terminal to do all sorts of crazy things, like...

Continue reading →

Life as a command line


View →

Thor - Awesome CLI apps

Ever wanted to create an awesome command line application but was lost in the sea of options parsing? Well, if you did, and even if you didn’t, Thor is here to help you.


But what is Thor exactly? It is a powerful toolkit for writing command line applications in ruby that is used in various well known projects such are Rails, Vagrant, Bundler, and similar. It can be even used as a replacement for rake for creating task like methods and functions.

Baby steps with Thor

When I stumble across something cool, my first instinct is to share and point out the most awesome parts of that thing. Usually, this is the worst approach for presenting things to other people. So now, I will try to hold back my geek instincts and start out simple. With a hello awesome world application. Here it is.

require "thor"

class  AwesomeHelloWorld < Thor

  desc "hello PLANET", "say hello to PLANET"

Continue reading →

Has_many :dragons


View →

Faster Git Workflow

How many times during a normal day you write git checkout or git commit –amend. Probably many, many times. Probably more than you want to admit without asking yourself what in the name of god made you choose this life path.

Nevertheless, I will try to improve that. Or at least I will try to make it hurt a little less.

Use g instead of git

This will save you two keystrokes per command, or even more. This is the simplest trick. Simply define an alias in your bashrc(or zshrc file if you have a hipster side) and assign git to the command g

alias g="git"

But why stop there? We can define g smarter. Instead of defining it as an alias we can define it as a function, and make it act like git status if invoked without parameters.


if [ "$" -eq 0 ]; then
  git status
  git "$*"

Put the above script in a ~/bin/g file, and append the following to your shells rc file


Continue reading →

Sinatra app with RSpec

There are times when the only thing I want to create is a simple API. In the Ruby ecosystem the standard for creating something simple is Sinatra. But, there are a lot of things you miss in Sinatra that you have predefined in Rails. Sinatra let’s you define and include only the things you actually need. Maybe this is a good thing, maybe it is not.

However, the things you need for a complete Sinatra application are sometimes hard to include. This tutorial aims to help you in that process, by showing you how to create a simple Sinatra web application that uses Rspec for testing.


We will create a simple TODO application with only two actions. One for listing all the existing Todos and another one for adding a new one. It will use Sinatra for creating the API, Rpsec for testing, and it will also include Active Support for adding a couple of nice functionality to the Ruby language.



Continue reading →

Alias method – CoffeeScript

In programming we like to reuse stuff. Data, variables, classes and even whole systems. We have a rule of thumb to only write code if it can not be found somewhere else. But sometimes the same thing can have a different meaning in a different context. So in order to reuse code but have a meaningful name in various contexts, we use aliases.


In CoffeeScript we don’t have an explicit alias method like in Ruby of Bash Script, but we have something better — functions as data.

Let’s start with the basics. To create an alias for a function we can just assign one value to the other

subtract = (a, b) -> a - b

minus = subtract

subtract(10, 6)     => 4
minus(10, 6)        => 4

If we have a method in a class, unfortunately we can’t just assign one value to the another because we would lose the context of the this value. Luckily, CoffeeScript has a nice little operator — @:: — that can...

Continue reading →

Progress bar for shell apps


Downloading a file, backing up your database, or installing a package for your system are all instances of long lived processes that we encounter daily. When such a process takes a long time to finish, it is always nice to give some kind of visual cue to the user.

A nice and space efficient way to achieve the previous is to use a progress bar or a display counter. This tutorial aims to help you create such an output for a console application.

The hardest part in creating such an output is to figure out how to clear the current line in the output and replace it with another. Well, there is a clever trick involved. Instead of using an \n at the end of the string that is printed to stdout, you can use the \r escape value. These two are familiar values but the first jumps to the start of the line and moves one line down, while the second only moves to the beginning of the line and thus...

Continue reading →


This is a continuation of the story about the Unicode standard. Read The ASCII table and The 8th bit if you haven’t already.


Last time I finished with a horrible story of overlapping encoding standards, and a general confusion in the software world. It was a world where a French scientists was unable to talk with a German friend.

The hero who solved all of the problems was the Unicode standard. It started with a simple idea. Collect all the symbols, create a big table, and assign a number to each of them. Oh, and try to be compatible with existing standards as much as possible.

When I said all the symbols, I really meant all the symbols. Music notes, Klingon and Emoji charactes are only some bizzare examples. Collecting all these symbols is much easier said than done, so there exists a consortium a.k.a the Unicode Consortium who is responsible for the whole standard.



Continue reading →

The 8th bit

In the last post I wrote about the ASCII standard. This is a continuation of that post.


The original ASCII standard takes up 7 bites, but the basic unit in the computer is 8 bites or 1 byte. This was the cause of a big problem in computing, casting it’s shadow even on the modern times.

Missing characters

The ASCII standard was perfect for the typical American user. But people from a non English speaking countries also wanted to store their texts. Unfortunately, the ASCII did not include all the characters they had in their alphabets.

Of course, everyone wanted to include the standard 128 character found in the ASCII table, but also some of their own characters. A lot of countries came up with the following scheme.

They would create a new 8 bits based table where the first 128 characters were taken from the ASCII table and the next 128 characters would be a list of characters from...

Continue reading →