Github Daily Commits

June, the beginning of the second half of the year, and yet no progress with my own personal scratch-an-itch project, see screenshot below.

Besides trying to walk 10k steps, read half an hour, write 100 words per day, I should add code 10 - 15 lines to my daily to do activities. Or as they said, daily Code Kata programming exercise. I have tried Project Euler, the list of challenging mathematical and programming problems, but gave up half way. As the name implied, is a set of challenging mathematical problems. I love to build stuff but solving time-consuming-and-getting-no-where mathematical problems? Not really my kind of fun and useful daily activity.

Again, code something, regardless how silly it is, just churn out something. Move ahead.

String to Array in PHP

Another interesting PHP  feature that I didn't realize. String can be accessed by both braces or array. Something I learned from reading my colleague's code. One of the benefit when you worked with people from different coding experiences.

My usual way of converting a string to array is first using str_split, then access individual character as array element. Example as shown.
php > $str = "foobar";
php > print_r(str_split($str));
Array
(
    [0] => f
    [1] => o
    [2] => o
    [3] => b
    [4] => a
    [5] => r
)
php > print_r(str_split($str)[0]);
f

However, the code above is unnecessary if you just want to obtain individual character in a string directly. For examples,

Using curly bracket or braces {}
php > $str = "foobar";
php > print $str{0};
f

Using bracket []
php > $str = "foobar";
php > print $str[0];
f

However, this only works for single-byte encoding strings as documented in the #PHP  manual.
"Internally, PHP strings are byte arrays. As a result, accessing or modifying a string using array brackets is not multi-byte safe, and should only be done with strings that are in a single-byte encoding such as ISO-8859-1." -- php.net, emphasis added

Detect Nudity in Images

It has been a while since I wrote any Python  script. Found this interesting Python library, nude.py which detects nudity in images. Some googling here and there just to refresh my memory on how to code in Python again.

First, install the library.
$ sudo apt-get install python-imaging
$ sudo pip install nudepy

Then, I wrote a tiny script to scan my Pictures folder for any nudity. The script is dog slow and can be optimized using multithreading. Next time, perhaps. On #1, you'll will to expand the expand the tilde manually.
import os, nude
from nude import Nude
from os import listdir
from os.path import expanduser

#1 expand tilde manually
path = expanduser("~/Pictures/")
files = listdir(path)
for file in files:
    n = Nude(path + file)
    n.parse()
    # ordinal is optional since Python 2.7 [3]
    tpl = "image {} has {} nudity"
    print tpl.format(file, "no" if n.result == False else "")

Result time.  Detection is quite accurate even with baby photos. However, occasionally the library will throw exception for certain black and white photos.

Note to self : Code more in Python.

Solving IT Turnovers Crisis

"On the first minute of the first day, an employee’s value is effectively zero. As that employee becomes acquainted with his new environment and begins to apply his skills and past experiences, his value quickly grows. This growth continues exponentially while the employee masters the business domain and shares his ideas with coworkers and management.
However, once an employee shares all of his external knowledge, learns all that there is to know about the business, and applies all of his past experiences, the growth stops. That employee, in that particular job, has become all that he can be. He has reached the value apex."
-- Alex Papadimoulis, emphasis added
One of the best thing re-read this year (the articles was written in 2008). The older and more experience your are, while still doing roughly the same thing, the faster for you to reach the value apex. Rather than waiting for the company to grow with you, work it out and bring changes to yourself. Be helpful and find new ways to be useful, assist your colleagues regardless the differences. Try learn a few new skills or hobbies. Move ahead. Start small and start something.

Notes on Total Daily Waking Steps in May 2013

Some notes on my total daily #walking steps in May 2013.

1. Maximum counted steps in that month, 17185 steps. But still cannot match my April best, which is around 23000+ steps.

2. The lowest in the month, 3525 steps. Can't remember why I didn't walk much that day. Maybe I was busy rushing for weekly software release or I was not feeling well.

3. Best week, 9th till 16th with a total of 7 days. Average more than 10000 per day. Sadly I can't keep the momentum going.

4. Dropped my #pedometer and damaged the LED display, the display text was barely readable. The pedometer survived washing machine twice but not an accidentally drop. Disappointed and demotivated. On 23rd, tried with another backup cheapo pedometer which was highly inaccurate. Gave up.

5. Same as 4. At the end of the month, start keeping track again as I bought myself another pedometer which is cheaper with similar features to my Omron. I will write about this in another post at another time.


Node.js in Ubuntu 13.04

Just realize my default Node.js in Ubuntu 13.04 was running older version. To upgrade to latest stable version, just follow the installation guideline.
$ sudo apt-get update
$ sudo apt-get install python-software-properties python g++ make
$ sudo add-apt-repository ppa:chris-lea/node.js
$ sudo apt-get update
$ sudo apt-get install nodejs

$ nodejs --version
v0.10.10