Upgrade Subversion Client to Version 1.7 in Ubuntu 12.04

Before upgrade your local working copy, you’ll need to clean up your working directory to prevent any errors during upgrade.
$ svn cleanup .

Upgrade your Subversion client from 1.6.x to 1.7.x in Ubuntu 12.04
$ sudo apt-add-repository ppa:svn/ppa
$ sudo apt-get update
$ sudo apt-get dist-upgrade
$ svn --version
svn, version 1.7.5 (r1336830)
   compiled Jun 26 2012, 22:39:53

Upgrade your local working copy
$ svn upgrade .
$ tree -L 1 .svn
.svn
├── entries
├── format
├── pristine
├── tmp
└── wc.db

Didn’t realize this until I read in the [documentation][3],
"However, some of the new 1.7 features may not be available unless both client and server are the latest version. There are also cases where a new feature will work but will run less efficiently if the client is new and the server old."
Now I understand why my local working copy does not has version 1.7 features. Both client and server must has the latest version. Question now is how to upgrade those ancient old client in CentOS ?

Installing and Using Jason A. Donenfeld's password-store in Ubuntu

Since I spend most of my time and console or browser, might as well use a console-based password manager.

Generate your PGP key, answer all the questions and remember your email address (e.g. me@example.com).
$ gpg --gen-key

Make sure your keys (both public and private) are generated successfully.
$ gpg --list-keys

Install password store. I put this in my own $HOME/bin directory. Make sure this path in within your $PATH.

Initialize your password file with the email address you used to generate the  #PGP  key in step 0.
$ pass init me@example.com

Add a sample password
$ pass insert email/gmail

List your password
$ pass ls

Copy password to clipboard
$ pass -c email/gmail

Parsing HTML Document Using PHP Native Extensions

While there exists many third party libraries to parse and process HTML documents, these libraries are too bloated when you just need to write a simple single file script. Hence the question is it possible to parse HTML using native built-in PHP core extension ? Yes, through DOM and DOMXPath. However, it will take a while before you’re familiarize with both APIs.

Below is a sample code to download, parse, and print all links from reddit main page. Note that when parsing HTML5 document, you will encounter "Tag time invalid in Entity" warning as DOM will default to HTML4 Transitional DTD which does not contains newer HTML tag. Just use @-operator to suppress the warning.

<?php
$html = file_get_contents("http://reddit.com");
$dom  = new DOMDocument();
@$dom->loadHTML($html);

$finder = new DOMXPath($dom);
$links  = $finder->query('//a[@class="title"]');
foreach ( $links as $link )
{
    echo $link->nodeValue . "\n";
    echo $link->getAttribute("href") . "\n\n";
}

Find Top-Level Domain (TLD) With MySQL

I was stuck with a problem of extracting Top-Level Domain (TLD) from a column in MySQL database. TLD is the last part of the domain name, example is the .com in google.com. As TLD varies in size, you may have you have .io (popular with startup), .com, or .name, how to you extract this part out without using any code but only SQL? Why SQL? Because it’s easier to group domain by TLD using GROUP BY clause.

Luckily, MySQL’s SUBSTRING_INDEX function can solve this problem easily. As the function name implies, extract a subset of a string into an index. First, let’s look at the function definition and parameters.

SUBSTRING_INDEX(str, delim, count)
  • str, the string we want to perform the action
  • delim, the delimiter we want to break the string into an index
  • count, maximum number of item from left (if positive), or from right (if negative) return

Examples:
mysql > select substring_index('111.222.333.444.555', '.', '1');
-> 111

mysql > select substring_index('111.222.333.444.555', '.', '2');
-> 111.222

Note : Negative count return result from the right
mysql > select substring_index('111.222.333.444.555', '.', '-1');
-> 555

mysql > select substring_index('111.222.333.444.555', '.', '-1');
-> 444.555

Back to my original question, how do we extract different TLD from a domain name?
mysql > select substring_index('www.google.io', '.', '-1');
-> io

mysql > select substring_index('www.google.com', '.', '-1');
-> com

mysql > select substring_index('www.google.name', '.', '-1');
-> name

Unfortunately, this only work with first level TLD and not second or later level like www.yahoo.co.jp where the TLD is co.jp.