Two useful YUM repositories for CentOS

EPEL pacakage

This is a repository maintained by the Fedora contributors, and is compatible with RHEL-derived distros. In my experience they all worked flawlessly. Useful packages including Node JS, Nginx, HAproxy, CouchDB and many other PHP modules.

To install the repo

To use it

Remi Release

Just discovered this repository recently, the packages are very up-to-date. As of today, there are PHP 5.4.11, MySQL 5.5.30.

To install the repo

To use it


* Update *

Seems EPEL decided to remove HAProxy from EPEL, if you want to install HAProxy, please check out this StackOverflow post.

Speed up your website with Google mod_pagespeed

In short, Google mod_pagespeed is a Apache HTTP server module that helps you optimize your web pages without changing a single lines of code in your web application.  In this article I’ll demonstrate how to get the mod_pagespeed up and running.

Note: This article is written for CentOS environment, if you’re using other Linux distros, please find the installation steps here.

Continue reading “Speed up your website with Google mod_pagespeed”

Inspect the view hierarchy (layout) of any Android app

Ever wondering how a particular app structure their hierarchy of views? With the latest Android SDK(I’m using 21.01 currently) and Eclipse ADT plugin, you can finally do that!

1. Connect your phone, Open the app you are curious about. Switch to the DDMS perspective, See the little button over there? click on it.insepct_view_hierarchy_1

2. The following screen will appear, you can now browse the view hierarchy just like a DOM tree which Web developers are familiar with.


What is does is basically dump a snapshot of the view in the current screen to the IDE. There’s quite a lot of information you can see in the “Node Detail” section, but you probably cannot reconstruct a layout XML in your own code by these info because It doesn’t show you some attributes like layout_width, layout_height, layout_weight etc. But it definitely tells you what types of views you need to build a particular layout.

Android: Can’t establish a reliable data connection to the server

Few days ago I saw this strange error message when I try to login my Google account on the HTC Desire (my previous phone):

Can’t establish a reliable data connection to the server

Since I cannot login to google, I cannot use the Play Store, Gmail, Youtube etc. My phone was connected to the home WiFi and the internet is definitely working.

I was thinking maybe this phone is already old and maybe Google changed something in their Authentication API. When I was about to give up after trying for about 10 times, I realize something Continue reading “Android: Can’t establish a reliable data connection to the server”

Install MongoDB PHP driver in CentOS 6.x

To use MongoDB in PHP, you are required to install a driver extension to the PHP environment. In CentOS, it’s in fact very straight forward.

Update 2015-March:

This tutorial works for CentOS 6.x, you can also do this by the following command,

You might first need the Remi Repo if you have not, tutorial on how to install that here.

If you use CentOS 7, you can also install by the above command without installing additional repo.

Original Post (Still works, and you will guarantee using the latest version of the mongodb driver):

Prepare the tools to build PHP extensions

This step is extremely easy with yum, but if you want to use the latest version of PHP, this article does not cover that.

Get the latest MongoDB PHP driver source

The source code is hosted in GitHub, you can find it here .

 Build the driver

The following steps are also mentioned in the readme of mongodb php driver

If all went well, the should be installed in /usr/lib64/php/modules/
now go to /etc/php.d

Restart Apache to make the change effective


Why Learning Android could improve your programming skills

Android is probably the most popular mobile operating system, a lot of programmers join the Android club to be an Android developer and turn their ideas into great apps. While some of you may not be interested in making a mobile app, but I would say you should give it a try. In this article I’ll try to convince you that you can improve your programming skills by studying the Android framework.

It’s simple

By simple, I don’t mean programming in Android is easy. The Google Android team has made it very easy for beginners to get started, just fire up the Eclipse IDE and load the examples and you have your first Android app. Through Android you’ll learn how to organize an app that is so simple to understand, write and deploy. You could apply this in organizing your web application. There’s a lot of good engineering practice in the Android framework. Of course, programming is never easy, if you feel that what you’re doing is easy, you maybe not making something useful!

It’s well documented

Learning Android is a joy. Continue reading “Why Learning Android could improve your programming skills”

Mirroring Github repos on your own server

We have already discuss why Git is so useful in managing your source code. Now you may also want to use git to check out some interesting projects from other gurus on open source code sharing platforms, e.g. GitHub. Sometimes you may want to mirror the repo on your own server so you and your team can access it from there instead.

A local copy of the foreign repo that is always up-to-date

For example somehow you and your team need to pull the Facebook Android SDK into their workspace, instead of everyone pulling it from Github, you can clone the repo into a local server, and everyone just pull from the local server. This technique can reduce redundant network traffic and is particularly useful if your team don’t have a fast and reliable internet connection, Continue reading “Mirroring Github repos on your own server”

Patterns for running Asynchronous code in Android (Part 1)

An important technique in Android Programming is to make potentially long task run asynchronously in your app, avoid blocking the UI thread, so your app feels more responsive. For example, downloading a file from the Internet, loading a media file from the external storage or applying a filter on an image bitmap etc. I will show you how to implement with AsyncTask, simple java threads and java Executor in Part 1.

Let’s say I want to load a bitmap from the internet, and set it to an ImageView , this might be what you’d write at first:

The Java way: simple Threads

You can implement it just like any other Java programs, define a Thread that does the job, and run it. Every Java programmer knows how to do that. Remember that if you want to modify the UI, you need to use runOnUiThread()

Continue reading “Patterns for running Asynchronous code in Android (Part 1)”