Tuesday, 21 January 2014

Practicing SQL

I was looking for ways to practice SQL online and I found three options:

1. SQLZoo. It's nice because it offers indications and tutorials on several topics of interest.

2. SQLFiddle. Doesn't have tutorials, but it's ready for you to just type your queries. 

The above should be OK for a quick test or practice. However, if you'd like to work on real data, then I think nothing comes even close to

3. STACKEXCHANGE DATA. Yes, you have real data available from all Stack Exchange websites. That includes over 6.5m Stackoverflow questions to query, not including users tables and what not. So excited I'm gonna hit the Publish button now and head to it. 

Saturday, 4 January 2014

Making your life easier with the terminal

There are several tricks that could help anyone become faster and more productive when working with the terminal. I wrote about several ways

1. Create aliases

A have a folder called "Programming" that I want to access very often from the terminal. Now typing "cd /home/alex/Programming" isn't a big deal, but I managed to shorten that to just "cdp", which is far more comfortable and a lot faster. But aliasing isn't just for shortening commands. You can also set a default behaviour to other commands. For example, if you want ls to list hidden files by default, you could create an alias for "ls -a" to be just "ls".

Creating aliases is easy: edit your .bashrc file and add your aliases line by line like this

alias ls='ls -a'

2. Use variables

There was a time when I wanted to move several files from different folders to the same folder (which had quite a long path). Then I had to repeat this a few minutes later, this time using other files. Instead of doing mv <my_files> <long_path_to_folder> over and over again, I saved the long path to a (short :D ) variable and used that instead, thus saving time. There are definitely better uses for variables, but I appreciated their existence. To create a new variable, type

varname=value

and then, to access its value use $varname.

3. Symbolic links

If you ever downloaded, for example, Eclipse or IntelliJ IDEA, you had to run the programs by typing something like <path_to_executable>/exec, which can get annoying after a while, especially, as in the previous situation, when you have a long path. Now I start IDEA by just typing idea in the terminal. Here's how it all works.

When you type a command in the terminal, that command is searched for in dedicated folders and, if found, is executed. We need to let those dedicated folders know that when we type idea in the terminal, then <path_to_idea>/idea.sh has to be executed. Welcome to symbolic links!

A symbolic link will hold a reference to your file. Go to /user/bin and type ln -s <path_to_idea> idea. You need to be superuser to run this. Then log out and log back in and now you can start IDEA (or whatever you want) using the command you've just set. :)