Connect to another server using public key

Compared to password authentication, public / private key authentication is a more secure way to connect from one server to another.

Do the following command from the host server you want to connect from:

ssh-keygen -t rsa

It will create private and public keys in your home directory, ~/.ssh/id_rsa and ~/.ssh/id_rsa.pub respectively.

What you need to do next is to go to the remote server, and append the entire content of id_rsa.pub from the host server at the end of ~/.ssh/authorized_keys on the remote server. This would allow remote server to recognise the public key of the host server. And, voila! Now ssh, scp, and rsync can work between the two servers.

Amazon Web Services: Free Usage Tier

Recently I am interested in Amazon AWS (Amazon Web Services), the cloud technology that companies are talking about in recent years. Amazon AWS provides cloud computing, of course in the “cloud“. So you can have your own server, in any geographic region (US, EU, or APAC), without really having to maintain the hardware.

What’s more, Amazon AWS is introducing Free Usage Tier, where you can try almost all of their services for free for a year, isn’t that great? You can get 750 hours of Amazon EC2 Linux Micro Instance usage (613 MB of memory and 32-bit and 64-bit platform support), or you can get Microsoft Windows-based Server if you want, together with all other supporting services (Elastic Load Balancer, Amazon S3, etc.).

SVN Update Dry Run

As a developer, when you are done with your code modification and you need to check the modification into the SVN repository, sometimes you may find that there are more recent version of the files you are modifying in the repository, especially when your project involves several developers. In this case, you may need to update your local copy to the latest version before checking those files in.

svn update .

The command above will update all files under the directory you are in. The trailing “dot” is required, and represents the current working copy you are currently in.

Sometimes, the update result can be surprising, as some of your modified local copies may have modified the same section as the most recent copies that you are trying to update with, thus it creates conflicts. You need to resolve the conflict by manually editing the conflicted files, or just simply accept any version of the files (working copy, or repository).

After sometime, I was wondering, if there is a way that I could know what would the update result be, that would be awesome! I will be able to know, which files are going to have conflict, and which files are safe to update.

After spending some time on searching, I found that this command could tell me what going to be the update result is:

svn merge --dry-run -r BASE:HEAD .

Specifying the revision BASE:HEAD will make the merge command behaves the same as the update command. It will show you what will be the result of the update command.

By using svn merge‘s --dry-run parameter, it will try the operation, without making any changes. So, no need to worry when a conflict happens. Just be prepared to resolve the conflict when you run the svn update command later.

Steve Jobs Biography

A few days ago, I bought this just-released Steve Jobs Biography, by Walter Isaacson, from Kinokuniya Singapore, where they offer 20% discounts for this book. What a great deal! Walter Isaacson is the same person who wrote Albert Einstein’s and Benjamin Franklin’s biography.

I’ve been reading other Steve Jobs’ books, one of which is “The Presentation Secrets of Steve Jobs“, which has been giving me great inspirations.

Looking forward to reading the life story about a person who transforms the world!

Facebook Timeline Is Still On Its Way

Still remember when Mark Zuckerberg presented on F8  about their biggest change yet, Facebook Timeline? In case you missed it, here’s the keynote presentation on F8, there’s a funny introduction by Andy Samberg pretending to be Mark Zuckerberg which you have to watch!

While rumor says that Facebook Timeline will be available for all Facebook users on 29 Sept 2011, there’s no sign of it until today, 2 Nov 2011. No one knows what could have caused the long delay.

However, Facebook Timeline is currently offered for Facebook developers. Here’s mine:

Facebook Timeline

Have you get your Facebook Timeline? If you want to convert your Facebook’s profile page into Facebook Timeline now, even before it is launched to most Facebook users, just simply drop a comment below.

Facebook Changes: You Just Need To Get Used To It

Every time Facebook changes their interface, these phrases might be very familiar to you: “Give me the old Facebook back!”, or “Facebook, please stop changing!”. By nature, users are not used to a change, because they will need to learn again from scratch. But ironically, they will still use Facebook, no matter how!

On 22 Sept 2011, Mark announced a “major” profile redesign called Facebook Timeline, which will be the biggest Facebook interface change yet. It will completely change the way users interact with Facebook. It will be available to most users on 29 Sept 2011. Let’s see how Facebook users react to it.

Using Memcached in PHP to Speed Up Websites

Memcached is a free, open-source, high-performance, distributed memory object caching system. Memcached uses RAM across multiple machines to cache key-value items. When used, memcached can make your website processed faster.

Memcache vs. Memcached in PHP

There are 2 PECL memcache libraries in PHP, memcache and memcached. Memcache is older, but more widely used; whereas memcached is newer, more feature rich, but less used. This wiki article explains the difference between the two libraries. Since it is more popular, memcache library is preferred.

Memcached In Action

In a very basic usage, memcached is used when trying to get a data. If the expected memcached key doesn’t exists (either never been created, or has expired), fetch the data from database, and set the memcache key for future use.

Here’s how it would look like in PHP:

// memcached configurations
$memcacheServers = array('host1', 'host2', 'host3');
$memcachePort = 11211; 

// initialize memcached
$memcache = new Memcache;
foreach($memcacheServers as $memcacheServer) {
  $memcache->addServer($memcacheServer, $memcachePort);
}

// memcached simple usage
$data = $memcache->get('mykey');
if (FALSE == $data) {
  $data = databaseQuery(); // get data from database
  $memcache->set('mykey', $data, 0, $expiryTime);
}

The program above will try to get mykey from memcached. It will fail initially, and will do database query and store the result in memcached for a specified expiry time. Subsequently, it will successfully get mykey from memcache, because it has been set before, until the memcached key expires.

The Original Google

Google has been evolving fast for the past few years. Just look at the newest Google look and feel, which has been greatly improved and consistent across all Google products.

Google Today

Despite all the greatness that Google has now, have you ever wondered, how did the original Google website look like? Some of you might not even familiar with Internet at that time. Back in 1997, here’s how Google looks like:

The Original Google

Looks familiar? What do you think?

Review Board: Take The Pain Out of Code Review

Code review has been an efficient way for engineers to maintain code quality. There are some ways that code review can be done. Over-the-shoulder lets reviewer look over author’s shoulder as the latter walks through the code. While pair programming (commonly implemented in extreme programming) is a method where two developers develop code together at the same workstation. Email pass-around could be the most commonly used method where developers are located all around the globe.

Review Board is one of the tool where tool-assisted code review comes in. Review Board consolidates all review request, lets you review codes, without any pain.

For the past month, I have troubled system team in my company to set up Review Board on one of our server. But all the efforts are paid off. At least, for my development team, where we normally use email to send out a review request, sees a light from it.

More people are involved in code review, and reviews are better in quality.

Since Review Board is introduced in my development team, there are more people involved in code review. I guess it’s because now it is easier for them to give reviews using Review Board, rather than sending out emails. Reviews are also better in quality.

Review in context makes code review easier

The best thing about Review Board is code reviews are done in context. To review codes, you only need to click on line numbers where you want to comment on, and type your review.

Knowledge Sharing

Review Board supports multiple projects and keep track of past reviews. Anyone can get back to older reviews and learn something from past reviews. Learning possibilities are endless.

Introducing Google+

You might have already heard of Google+, Google’s newest social networking site, that is after Facebook.

Right now, Google+ is under field trial, which allows only invited people to get in and try Google+. If you haven’t get one, you might need to wait until Google+ is available for public.

Google+ vs. Facebook

Google+ introduces “circle”, which is more like “friend” in Facebook. To add friends in Google+, you need to add people to your circle. Unlike Facebook, Google+ adopts asymmetric follow. It means that you can add other person to your circle without him adding you to his circle.

Learn More

You can learn more about Google+ if you haven’t get an invitation yet.

Mozilla Firefox 5 is Released!

Firefox 5Not long after Mozilla Firefox 4 was released on 22 March 2011, Mozilla Firefox 5 is released today, 21 June 2011, and is ready for download!

Although the Graphical User Interface hasn’t been changed since version 4, Mozilla Firefox 5 features improved HTML5 and CSS3 support, improved overall performance, and a Do-Not-Track option.

Download the latest version of Mozilla Firefox now!

jQuery Dialog Plugin: SimpleModal

jQuery UI provides “dialog” widget for jQuery, which is easy to use, and is already integrated into the jQuery UI core. However, jQuery UI’s dialog widget isn’t easy to style, and most of the time you can only use jQuery UI’s ThemeRoller to edit your widget’s style.

After looking for several jQuery dialog alternatives, finally I found one dialog plugin that meets my requirements: fancy, simple, and clean.

SimpleModal is a lightweight jQuery Plugin which provides a powerful interface for modal dialog development. Think of it as a modal dialog framework. SimpleModal gives you the flexibility to build whatever you can envision, while shielding you from related cross-browser issues inherent with UI development.

As it’s name describes, SimpleModal is very simple in design, and that’s what other dialog plugins might not have.

NTU Campus Interview: Common Mistakes

Today, 6 June 2011, I went for NTU Campus Interview event to interview some candidates to fill various position in my company.

There were huge interest from NTU students, which mainly are master degree graduates. Some positions offered are Software Engineer, Software Process Engineer, and System Engineer.

Despite all the great talents, I spotted some common mistakes from some interviewees:

  1. Didn’t do their homework
    It’s a big turn off for an interviewer when he / she found “I don’t know”, or “I’m not sure” answer when he / she ask “What do you know about our company?”
  2. Applied for a position because of study field
    There is nothing wrong when you apply a position because you learn that field in your studies. But most importantly, apply for a position that you enjoy yourself in.
  3. Didn’t read requirements well
    Some are applying just to get any position without reading the requirements, with a completely different skill sets.

These common interview mistakes must be avoided at all times, and do prepare yourself before going for an interview.

Online Photo Editor – For Free

Whether you are a web designer, or a web developer, photo editor is a must-have software. The most popular photo editing software out there is very expensive. Even if you can afford it, not all of its features are useful for you.

Introducing pixlr, a free photo editor that runs in your browser. No download, no software, no license required. I, myself, as a web developer, find it very useful to help me in developing websites. Whether to crop an image, make a transparent image, resize an image, or make an image from scratch, pixlr editor can do it for you. The features are quite rich, and almost all basic image editing can be done with pixlr. And the best part, it’s FREE!

Faster Websites: HTTP Caching

Cache is local copies of resources, stored in browser for future use. There are at least 2 advantages when you set the cache for your website properly:

  • Users load your web pages faster for their subsequent visit
  • Less load for your web server

Cache mainly useful to keep static resources, like images, CSS, and JavaScript files, because they don’t change often.

The key to making the cache work effectively is the HTTP caching headers, which are sent by the web server to specify how long a resource is valid and when it last changed. There are two HTTP headers to define how long a resource is valid:

  1. Expires – specifies a date after which a resource is invalid. After that point, the browser will ask for the resources again.
  2. Cache-Control: max-age – specifies how long a resources is valid after it is downloaded.

The recommended value for both headers for static resources are at least one month in the future, but preferably a year in the future. You only need to set one of the two headers. If you set both, the Cache-Control header overrides the Expires header.

If you’re running Apache on your web server, you can set the HTTP headers using .htaccess file.

PHP: Echo or Print? Are Parentheses Required? Single or Double Quotes? And More..

Echo or Print?

There are 2 main functions that are commonly used by PHP developers to output a string: echo and print. The question is, which one is better?

echo("Hello World!");
print("Hello World!");

They are fairly do the same exact thing, but echo is definitely faster than print.

Are Parentheses Required?

Here’s the fact: echo and print are both not actually a real function, but they are language constructs, so we are not required to use parentheses with its argument list.

All of the following statements are correct:

echo("Hello World!");
print("Hello World!");
echo "Hello World!";
print "Hello World!";

Single or Double Quotes?

Given the following examples:

echo "My name is $name";
echo 'My name is $name';

The first statement would output something similar to “My name is Irwan“, while the second statement would output exactly “My name is $name“. Why? Because double quotes parse variables, while single quotes don’t.

Should we always use double quotes? No. Single quotes are at least 4 times faster than double quotes in any situation. We should always use single quotes whenever possible.

This is better:

echo 'My name is ' . $name;

And more..

This is tricky, which of these statements are the fastest?

echo "My name is $name and I am still learning PHP";
echo "My name is " . $name . " and I am still learning PHP";
echo 'My name is ' . $name . ' and I am still learning PHP';
echo 'My name is ' , $name , ' and I am still learning PHP';

In the above, we have learned that single quotes are always faster than double quotes. So it’s between statement 3 and 4. Since echo is a language construct that accepts parameters, we can use comma-separated parameters instead of string concatenation. The answer: Statement 4 is the fastest because the PHP compiler will save time on concatenating strings.