Note to self - 2014-06-19

I've a feeling that Vagrant and Google Chrome hates each other. I can understand Vagrant or Virtual Box is resource intensive but Chrome with just one tab with Gmail opened? Seriously?

The curse of PHP. Once you've been stereotyped as programmer of certain programming language, is hard to switch or move to another language.

Talking about being absent minded. Nearly lost my whole bag, didn't realized it until I traveled for hours.

Development and Production Environment

Always match your development environment with the production environment, this is so true especially for Python development. While the Docker just reached 1.0, the preferable choice still is Vagrant. Will look into Docker once time permitted. Off course, having a quad-core machine with plenty of RAMs help a lot as well.

Which begs the question, if I'm going to buy a new machine that support visualization, which Xeon model of socket 1150 should I get so the total cost of the system is within the budget of MYR1.5k? Unless necessary, I don't believe in paying more than MYR2k for any electronic devices these days.

Upgrading system is always a tedious process. You've appreciate the effort done on the unit testing, it will give you some sort of assurance that everything work as it. Testing, is one area that I should focus on in coming years.

mkdtemp: private socket dir: Permission denied

Woke up this morning and my GDM login kept kicking me out of the login. Ctrl+Alt+F1 back to the console shell and check all the logs message. Based on the similar incident I've faced few months back, check the the .xsession-errors file. Result as shown.

Go to my home directory.
$ cd

Read the X's session log file for some clue.
$ cat .xsession-errors
/etc/gdm3/Xsession: Beginning session setup...
localuser:kianmeng being added to access control list
openConnection: connect: No such file or directory
cannot connect to brltty at :0
Script for scim started at run_im.
Script for auto started at run_im.
Script for default started at run_im.
mkdtemp: private socket dir: Permission denied

Googled around, it seemed that this is quite a common issue. To confirm my finding.
$ ls -ld /tmp
drwxr-xr-x 17 root root 20480 Jun 15 12:42 /tmp/

Applied the fix.
$ sudo chmod a+wt /tmp

What is the actual root cause? Last I remembered, I was restarting the machines repeatedly without login to the machine, for some BIOS settings tweaking. Most likely that's reason.

Setting Up Git Repo Locally and Push to Remote

To be more specific, how do you setup a local Git repository with branches and tags and then later push to remote origin URL? It turned out to be quite simple. Steps as follows.

1. Setting up the remote central bare project repository.
$ mkdir project
$ cd project
$ git init --bare

For any central shared Git repository, use the --bare parameter to prevent What's the difference between a normal and bare repository? A normal repository contains a working directory and actual repository, the hidden .git folder. Where the bare repository contains only the contents of .git folder.

If you're coming from the Subversion background, you'll notice that the repository data and your check out repository has different tree layout.

2. Setting up your local project repository.
$ mkdir project
$ cd project
$ git init

3. Add in all your code, branches, or tags if necessary.

4. Set the remote origin URL.
$ git remote add origin git@github.com:foobar/project.git
$ git remote -v
origin  git@github.com:foobar/project.git(fetch)
origin  git@github.com:foobar/project.git(push)

4. Push all your branches and tags to the remote origin URL.
$ git push REMOTE --tags
$ git push REMOTE --all

Setup Backports Repository for Debian Wheezy


Setup procedure are quite easy but unfortunately, not many packages available especially the latest kernel in the backports repository.
$ sudo sh -c 'echo "deb http://cdn.debian.net/debian wheezy-backports main" > /etc/apt/sources.list.d/wheezy-backport.list'
$ sudo apt-get update
$ sudo apt-get -t wheezy-backports install --reinstall tmux

To find all installed backport packages. [2]
$ sudo dpkg -l | awk '/^ii/ && $3 ~ /bpo[4567]0/ {print $2}'

Explanation of the awk command. Find all line that start with 'ii' characters and the third column contains the word bpo40 or bpo50 or bpo60 or bpo70. If found, print the second column.

Git Learning Progress

Is like one of those rare day where you found enjoyment and gained achievement through learning something new. As I'm slowly getting acquaintance with Git, the more I use it, the more I understand how it supposed to work. More on that in another post. Right now, regarding my skill on Git, on a scale of 1 to 10, I rate myself around 3.

Moving Away From PHP

This is probably the main reason why Perl was dethroned from its position as one of the leading programming language. Its role has been replaced by other more simpler programming language as in the web (PHP) and system admin (Python/Ruby). I was wondering, what will replace PHP, Python, or Ruby? Is PHP going to be replaced by Hack (by Facebook) or node.js or Python/Ruby being replaced by Golang?

Reflecting back my programming career. I made a mistake not moving away from PHP. I should have invested more times in other programming language like Java or Python, especially Java. Off course, mistakes were made and nothing much we can do beside accepting it and move ahead.

Is always good to try and learn different new technologies. Most importantly you must enjoy what you're doing and stay healthy to sustain it.

Note to self - 2014-06-08

One of the benefit of writing a journal is that you'll have the opportunity to reflect back and monitor your progress of your life. Especially how you got where you are right now.

Due to nature of my workplace, I'm slowly getting into the habit of weekly review and keep track of my time usage, something that may be frowned upon by others, but I believe is the right approach if you want to be very aware of you time usage.

For the past two days, I've switched my working style. No more coding with a lappy while lying down. Just sat at my table with dual-monitors and code and write. The noisy workstation still bother me but I'm slowly getting used to it. Productivity seems to increase and you seemed to accomplish something. Whether this is the right thing? Not sure.

While I'm a firm believer in computer user freedom and even set up a monthly donation to them, but what's my Free Software Activities? Sadly, none. However, what if I allocate two to three hours per week for such activities. Let's see how this goes.

More on Bash scripting. I've learned and relearned quite a few things today while writing a small script for setting up my development machine.

The Weirdness of Ruby Version in Debian Wheezy

Due to certain application dependency on Ruby, I need to install Ruby on the machine. As you can see from below, the versioning and packing in Debian puzzled me.

Install the latest Ruby version and the ruby-switch program which will can set the default Ruby version to any installed version.
$ sudo apt-get install ruby1.9.3 ruby-switch

Check our just installed version.
$ ruby --version
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]

Show the list of available version. Note that listing shows ruby1.9. I thought we've just installed version 1.9.3?
$ sudo ruby-switch --list
ruby1.8
ruby1.9.1

Set version 1.9.3 as our default Ruby version.
$ sudo ruby-switch --set ruby1.9.1

Check the binary of ruby. Apparently it is a soft link.
$ file `which ruby`
/usr/bin/ruby: symbolic link to `/etc/alternatives/ruby'

Again, another soft link but pointed to ruby1.9.1.
$ file /etc/alternatives/ruby
/etc/alternatives/ruby: symbolic link to `/usr/bin/ruby1.9.1'

Check whether /usr/bin/ruby1.9.1 is a binary or soft link. As result shown, it's a binary program.
$ file /usr/bin/ruby1.9.1
/usr/bin/ruby1.9.1: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.26, BuildID[sha1]=0xf5d1e1e2959315b9d4907b6a40fb2c44f1c27c87, stripped

Check the ruby1.9.1 version again. What?! Why it's showing version 1.9.3?
$ /usr/bin/ruby1.9.1 --version
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]

Check which package contains this /usr/bin/ruby1.9.1 binary. Weird, it belongs to ruby1.9.1 package, which is reasonable but I didn't install that.
$ apt-file search /usr/bin/ruby1.9.1
ruby1.9.1: /usr/bin/ruby1.9.1

Show the reverse dependancies. Why ruby1.9.1 needs ruby1.9.3?
$ apt-cache rdepends ruby1.9.1 | grep ruby
ruby1.9.1
ruby1.9.1:i386
libstfl-ruby1.9.1
ruby1.9.3
ruby1.9.1-full
ruby1.9.1-examples
ruby1.9.1-dev
ruby

Okay. Let's check with Ruby Gem. Similar steps.
$ file `which gem`
/usr/bin/gem: symbolic link to `/etc/alternatives/gem'

$ file /etc/alternatives/gem
/etc/alternatives/gem: symbolic link to `/usr/bin/gem1.9.1'

Interesting. gem1.9.1 is a ruby script.
$ file /usr/bin/gem1.9.1
/usr/bin/gem1.9.1: Ruby script, ASCII text executable

However, when checking the version of /usr/bin/gem1.9.1.
$ /usr/bin/gem1.9.1 --version
1.8.23

What the heck?!

More on Bash Scripting

1. For anything that don't needs to be escaped a lot, sudo sh -c is good enough.

2. I've not even to begin to explore the power of sed, the stream editor. Example here is to insert a line to the beginning of a file. More reading on the one-line scripts for Sed in coming months.
$ sudo ls -l /root | sudo tee /root/ls.txt > dev/null
$ sudo sh -c 'ls -l > /root/ls.txt'

3. "Syntax error: "(" unexpected". That's the error you got when you tried to run a Bash script through Dash without the shebang line, which is the default system shell for Ubuntu or Debian.

4. It will take a while to appreciate the concise syntax of Bash. Let's look at these two examples [9] where we restart a daemon upon a missing file.

Ex1: Typical version
if [ ! -f /tmp/daemon.pid ]; then
python daemon.py restart
fi

Ex2: Concise version
[ -f /tmp/daemon.pid ] || python daemon.my restart

The [] constructor check the existence of the file and return *0 on success* and any number than 0 as failure. Yup, zero as success status compare to other popular programming language. Reason is you can return many different codes as error status but only one code to represent success.

Meanwhile, the || construct will execute the command on the right only if the command on the left fail.

Monitorix

"Monitorix is a free, open source, lightweight system monitoring tool designed to monitor as many services and system resources as possible. It has been created to be used under production Linux/UNIX servers, but due to its simplicity and small size can be used on embedded devices as well."
--http://www.monitorix.org, emphasis added.
Installation guide for Debian.
$ sudo su -
# curl http://apt.izzysoft.de/izzysoft.asc | apt-key add -
# apt-get update
# apt-get install monitorix
# service restart monitorix
# exit
$ xdg-open http://localhost:8080/monitorix/

One should not reject the opportunity of the visual pleasure from his machine.

Note to self - 2014-06-07

Most chassis and CPU fans use either a three pins or four pins connector. Not for HP Proliant server, different and proprietary. Their fan connector has six bloody pins. To make matter worse, these fans, sounds like a bloody vacuum cleaner. Imagine sitting next to that machine with a dbA of 79! No, you can't unplug the fan, Power-on self-test (POST) will fail!

Next time be extra careful when you're looking for a battle station. Remember to check the motherboard carefully, especially the noise and parts. Most server board contains proprietary pins and it's not easy and cheap to source these replacement parts.

If I can't still find another way to resolve this noise issue, I'll need to start another fund to get another Xeon-based quad-core workstation. Why Xeon and not i7/i5 ? Well, is not a gamer gig and furthermore, is nice to have make -j N.
                                     
Always find a way to speed up your daily routine. Pick anything around you that can be automated. As someone who spent roughly 50/50 of his time between the console and a browser, it never occurs to me that you can google from command line.

Lots of Bash coding today. Not sure why, I'm kind of have a certain liking to Bash script. Today I learned about shell bultin, passing all arguments to a function using "$@", and ``backtick and $(cmd) for command substitution. The latter is preferred because you can have nested commands.

Launch Default Web Browser From Console

Interesting, never realize there are so many ways. I should update my way of writing step-by-step guide.

1. sensible-browser
$ sinsible-browser http://google.com
$ man sensible-browser | grep DESCRIPTION -A 3
DESCRIPTION
sensible-editor, sensible-pager and sensible-browser make sensible decisions on which editor, pager, and web browser to call, respectively. Programs in Debian can use these scripts as their default editor, pager, or web browser or emulate their behavior.

2. xdg-open
$ xdg-open http://google.com
$ man xdg-open | grep DESCRIPTION -A 3
DESCRIPTION
xdg-open opens a file or URL in the user's preferred application. If a URL is provided the URL will be opened in the user's preferred web browser. If a file is provided the file will be opened in the preferred application for files of that type. xdg-open supports file, ftp, http and https URLs.

3. x-www-browser
$ x-www-browser http://google.com
$ man x-www-browser
No manual entry for x-www-browser
See 'man 7 undocumented' for help when manual pages are not available.

$ ls -l `which x-www-browser`
lrwxrwxrwx 1 root root 31 Feb 22 21:08 /usr/bin/x-www-browser -> /etc/alternatives/x-www-browser

$ ls -l /etc/alternatives/x-www-browser
lrwxrwxrwx 1 root root 29 Feb 23 04:10 /etc/alternatives/x-www-browser -> /usr/bin/google-chrome-stable

No wonder, is Debian alternative system.
$ sudo update-alternatives --list x-www-browser
/usr/bin/google-chrome-stable
/usr/bin/iceweasel
/usr/bin/midori

4. gnome-open
$ gnome-open http://google.com
$ man gnome-open | grep DESCRIPTION -A 2
DESCRIPTION
This program opens files using file handlers configured in GNOME.

Note to self - 2014-06-05

1. Taobao, slowly but surely, will replace the local ecommerce players as the go to destination for online purchasing. Nothing interesting among them, just another reseller of items procured from merchants in Taobao. The real money or profit still flow through logistic, or to be specific, freight forwarder.

2. Watching items being purchased online in real-time was quite an additive activity. You will be surprised by the types of item purchased online and some of these items are dirt cheap! I'm so going to create a dashboard to load these purchases using my underutilized monitor.

3. What do you call a PHP programmer who are in the midst of switching to another programming language like Python? A better PHP programmer. Ouch.

4. PHP vs. Python. Python is a better when you want to learn more about programming in general or be a better developer. While PHP is great when you want to create something fast for the web. Contrary to popular belief, Python is not a beginner friendly language. By the way, PHP is a web template language. Which one makes you happy? Neither. But is good to finally escape from PHP after all these 10 years. For me, PHP is "cari makan" and Python is to stimulate my bored mind.

5. export PYTHONDONTWRITEBYTECODE=1
Yup. No more pyc files scatter around. Only for Python 2.6 though.

6. Read the bloody change logs. Seriously, when you're upgrading any software or libraries, please remember to read the bloody change logs.

7. Awareness, acceptance, and courage are the keys to become a better estimator. First, you must aware of your current situation. Second, you must accept the current limitation either in your or your surrounding. Third, you must have the courage to make hard decision and mistakes to go ahead.

Note to self - 2014-06-06

Never get yourself burned by Python libraries incompatibility issues again. Is like you're lost in a maze and keep returning to the same old spot.

Learning two programming at one time? Overwhelming but it a fun stimulating experience. I should be more aggressive and start churning out stuff.

Average emails wrote per day this week? Two. More opportunity to practice my writing and communication skills..

When you realized that you forgot to eat your lunch, it implied two things. Either you're too occupied with your current task or you've fscked up your digestive system. I'm both.

Are you a pragmatic or idealist programmer? Neither. Stop asking and just coding. Create. Build. Start.

Unexpected Inconsistency: Run fsck Manually

Surprised to see this when I booted up my workstation upon arriving home. Booted up my lappy and googled for answer. Keyed in the password and ran the fsck command manually.
$ fsck /dev/sda

Reboot the machine. Same message again. Suddenly noticed that the system date was showing year 2011. Realized that I took out the motherboard's battery but forgot to reconfigure back the system date and time.

Restart again into BIOS settings. Update the system date and time and everything works again.

Next step, update your clock accurately.
$ sudo apt-get install ntpdate
$ sudo nptdate ntp.pool.org
$ date