Lifelong Learning

Via HN. Interesting article on rules to follow for lifelong learning by Richard Hamming, widely known for Hamming code, an error-correcting code used in telecommunication industry.

For a software developer, lifelong learning is crucial if you want to sustain your passion and extend your career. Similarly to fashion modelling or idols, ageism in software development is real and unavoidable. For non-technical people point of view, is always cheaper and easy to manage (ahem manipulate) young blood. This is true where the organization have limited budget and the developed system is just non-critical plain CRUD app.

The first rule resonates with me. Knowing the fundamental is understanding how things works as compare to get things to work. For example, using any programming languages to build a website is getting things to work. Knowing how the HTTP protocol works with all its intricate parts is understanding how things works. Many years ago, in FOSS world, Perl was the default choice to build any website. Later it was dethroned by PHP, and in a short while, Ruby due to Rails, and now Javascript which is ridding on Node.js popularity. Regardless the current trending programming language used for building a website, the fundamental part still remains the same. Hence, to stay relevant, focus on the fundamental.

Judging by my current career detour right now, this is the best time to pick up the fundamental again.

Solving Project Euler's 1st Question Using Nim Programming Language

Nim is the trending programming language in the HN which bears similarity to Python. I was intrigued with it and decided to learn it by solving the first question of Project Euler. This programming language felt like a mixture of both Python and Ruby but that too early to tell as I haven't explore the other distinct features of the language.

To reduce the verbosity, which was set to default 1, during compilation, I've created a Bash alias compile(c) a Nim source and run(-r) it but set the default verbosity level to 0. You will see nimc alias being used in the subsequent examples.
alias nimc='nim c -r --verbosity:0'

First, let's loop from 1 till 999 and print all the number. Type the below code
and save it as p1.nim.
for i in 1..999:
  echo i

Compile and run it. You should see an output as shown.
$ nimc p1.nim
1
2
......
998
999

Next, we filter and print only number which are either a multiples of 3 or 5.
for i in 1..999:
  if i mod 3 == 0 or i mod 5 == 0:
    echo i

Compile and run it again.
$ nimc p1.nim
3
5
......
996
999

Lastly, to find the sum of all numbers which are the multiple of 3 or 5 below 1000.
var 
  sum: int;

for i in 1..999:
  if i mod 3 == 0 or i mod 5 == 0:
  sum = sum + i

echo sum
assert(sum == 233168)

Alternately, a different solution using Arrays.
type
  IntArray = array[1..999, int]
var 
  total = 0 
  x: IntArray

for i in low(x)..high(x):
  if i mod 3 == 0 or i mod 5 == 0:
    total += i

echo total
assert(total == 233168)

Result of the both solutions.
$ nimc p1.nim
233168
233168

Oracle MySQL in Fedora Rawhide (F22)

Due to some constraint, I need to install Oracle MySQL community version in Fedora Rawhide (F22) instead of using the default MariaDB. Installation procedure through Yum repository as follows:

Download and install the Yum repository rpm. We will download the latest version available which is for F21. No worry, we will fix the release version not found issue later. Note only rpm command support installation directly through an URL instead of yum command.
$ sudo rpm -ivh http://dev.mysql.com/get/mysql-community-release-fc21-6.noarch.rpm
Retrieving http://dev.mysql.com/get/mysql-community-release-fc21-6.noarch.rpm
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-release-fc21-6   ################################# [100%]

To check that the MySQL Community repositories have been installed properly.
$ yum repolist | grep mysql
mysql-connectors-community/22/x86_64 MySQL Connectors Community             3
mysql-tools-community/22/x86_64      MySQL Tools Community                  1
mysql56-community/22/x86_64          MySQL 5.6 Community Server            32

Next, update our locate RPM database with newly installed MySQL repository package. Unfortunately, as I mentioned earlier, the repository does not contains packages for F22 release.
$ sudo yum update
Loaded plugins: aliases, fastestmirror, remove-with-leaves, yum-fast-downloader
http://repo.mysql.com/yum/mysql-connectors-community/fc/22/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found
Trying other mirror.
http://repo.mysql.com/yum/mysql-tools-community/fc/22/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found
Trying other mirror.
http://repo.mysql.com/yum/mysql-5.6-community/fc/22/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found
Trying other mirror.
Loading mirror speeds from cached hostfile
 * rpmfusion-free-rawhide: mirrors.tummy.com
 * rpmfusion-nonfree-rawhide: mirror.bjtu.edu.cn
No packages marked for update

If we look into the MySQL Community repository file, we can see that we need to change the $releasever variable.
$ cat /etc/yum.repos.d/mysql-community.repo | grep baseurl
baseurl=http://repo.mysql.com/yum/mysql-connectors-community/fc/$releasever/$basearch/
baseurl=http://repo.mysql.com/yum/mysql-tools-community/fc/$releasever/$basearch/
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/fc/$releasever/$basearch/
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/fc/$releasever/$basearch/

Now, we're going to check the values of these yum variables as seen above using yum-debug-dump command.
$ sudo yum-debug-dump
Loaded plugins: fastestmirror, remove-with-leaves, yum-fast-downloader
Loading mirror speeds from cached hostfile
 * rpmfusion-free-rawhide: mirrors.tummy.com
 * rpmfusion-nonfree-rawhide: mirror.bjtu.edu.cn
Output written to: /tmp/yum_debug_dump-butterfly-2015-02-15_03:47:14.txt.gz

$ zcat /tmp/yum_debug_dump-W08LAP040-2015-02-15_03\:47\:14.txt.gz  | grep "YUM INFO" -A 3
%%%%YUM INFO
  arch: ia32e
  basearch: x86_64
  releasever: 22

Replace the $releasever manually with Fedora version F21 as it should let us install it without issues.
$ sudo sed -i 's/$releasever/21/g' mysql-community*
$ sudo cat mysql-community* | grep baseurl
baseurl=http://repo.mysql.com/yum/mysql-connectors-community/fc/21/$basearch/
baseurl=http://repo.mysql.com/yum/mysql-tools-community/fc/21/$basearch/
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/fc/21/$basearch/
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/fc/21/$basearch/
baseurl=http://repo.mysql.com/yum/mysql-connectors-community/fc/21/SRPMS
baseurl=http://repo.mysql.com/yum/mysql-tools-community/fc/21/SRPMS
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/fc/21/SRPMS
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/fc/21/SRPMS

Re-update all Yum repositories again.
$ sudo yum update
Loaded plugins: aliases, fastestmirror, remove-with-leaves, yum-fast-downloader
mysql-connectors-community                            | 2.5 kB  00:00:00     
mysql-tools-community                                 | 2.4 kB  00:00:00     
mysql56-community                                     | 2.5 kB  00:00:00     
Loading mirror speeds from cached hostfile
 * rpmfusion-free-rawhide: mirrors.tummy.com
 * rpmfusion-nonfree-rawhide: mirror.bjtu.edu.cn
No packages marked for update

Lastly, installation of both the MySQL Community client and server.
$ sudo yum install mysql-server mysql

Raspberry Pi 2 : Installation

Tail your kernel log and insert your SD Card. Below is the result I obtained from my lappy.
$ sudo tail -f /var/log/messages
......
Feb  8 03:15:27 butterfly kernel: [16266.527753] mmc0: new high speed SDHC card at address aaaa
Feb  8 03:15:27 butterfly kernel: mmc0: new high speed SDHC card at address aaaa
Feb  8 03:15:27 butterfly kernel: [16266.528442] mmcblk0: mmc0:aaaa SL08G 7.40 GiB 
Feb  8 03:15:27 butterfly kernel: mmcblk0: mmc0:aaaa SL08G 7.40 GiB 
Feb  8 03:15:28 butterfly kernel: [16266.538560]  mmcblk0: p1
Feb  8 03:15:28 butterfly kernel: mmcblk0: p1

Or list our our SD Card block device. Note that MMC stands for MultiMediaCard where the naming convention, mmcblk{id}{partition} is used in GNU/Linux.
$ lsblk | grep mmc
mmcblk0                                       179:0    0   7.4G  0 disk  
└─mmcblk0p1                                   179:1    0   7.4G  0 part 

Confirm again through local file system.
$ ls -l /dev/mmc*
brw-rw----. 1 root disk 179, 0 Feb  8 03:15 /dev/mmcblk0
brw-rw----. 1 root disk 179, 1 Feb  8 03:15 /dev/mmcblk0p1

As the time of writing, the there are only four Operating System images available for Pi 2. We're going to download both Raspbian (Debian Wheezy) and also recently release Snappy Ubuntu Core, a minimal server image. For faster download, use a download manager that support multiple connections download. I'm using aria2 with four concurrent connections as shown below.
$ aria2c -x 4 http://downloads.raspberrypi.org/raspbian_latest
$ aria2c -x 4 http://downloads.raspberrypi.org/ubuntu_latest

$ ls -lh 2015*.zip
-rw-rw-r--. 1 ang ang 977M Feb  7 03:05 2015-01-31-raspbian.zip
-rw-rw-r--. 1 ang ang 679M Feb  8 03:55 2015-02-03-pi-snappy.zip

To verify that you've downloaded both images successfully, generate the SHA-1 hash value locally and then copy it and search against the downloads page.
$ sha1sum 2015*.zip
0171e77f687c447dae32609fcc6aa700c750d6f5  2015-01-31-raspbian.zip
4ca8ea6b694ad644cf4b00337a625b28bc8f8455  2015-02-03-pi-snappy.zip

Uncompress both download images. Note that you need to add single quote for the unzip program to work on multiple zip files.
$ time unzip '2015-0*.zip'
Archive:  2015-01-31-raspbian.zip
inflating: 2015-01-31-raspbian.img  

Archive:  2015-02-03-pi-snappy.zip
inflating: pi-snappy.img           

2 archives were successfully processed.

real    2m24.316s
user    1m7.767s
sys     0m4.985s

As you can see from the uncompress file size of both images, is best to get a SD Card with size equal or more than 8Gb if you wish to install or store more data to it.
$ ls -lh *.img
-rw-r--r--. 1 ang ang 3.1G Jan 31 21:36 2015-01-31-raspbian.img
-rw-r--r--. 1 ang ang 2.8G Feb  3 15:06 pi-snappy.img

Following the installation guideline for GNU/Linux using command line tools, we're going to write the image (Raspbian first) to the SD card using the dcfldd program, which show progress instead of disk dump (dd) program.
$ sudo yum install dcfldd
......
$ time sudo dcfldd bs=4M if=2015-01-31-raspbian.img of=/dev/mmcblk0
768 blocks (3072Mb) written.
781+1 records in
781+1 records out

real    4m50.750s
user    0m0.017s
sys     0m8.754s

Remove your SD card and insert into your Pi and boot up the machine.

Raspberry Pi 2 : Hardware

The next generation of Raspberry Pi 2 has been recently released and on sale for USD 35. Instead of sourcing it through local MY distributor (slow and expensive as well), I bought it directly from element 14 which costs me around MYR 118 with free shipping. Surprisingly, instead of posted delivery date in the website, they shipped the board to me directly the next available day after confirmed payment!

Why getting this Pi 2? Two main reasons. First, ARMv7 processor support where you can install any available ARM GNU/Linux distributions and Windows 10. Secondly, better hardware specification of 900Mhz quad-core ARM A7 CPU and 1Gb RAM, which surely will give me a better media experience compare to Pi 1.

Unfortunately, you will need to spend more money to set everything up. There is no available casing for Pi 2 yet and the I can't reuse back my original Pi 1 casing. But I can live with that. Also, I've misplaced my micro SD card and need to get a new one instead. Checking against the available and working SD cards, I ended up purchasing SanDisk 8GB MicroSD Memory Card [SDSDQM008GB35A] which cost me MYR 15. There are cheaper card but I opted to be safe and the card also came with an adapter.

Next, continue with Operating System installation.