git pull – force overwrite your code with remote or local changes

Conflicts can be troublesome when you do a git pull or git merge. What if you are pretty sure that you want to use the remote version or your version of the code during a pull/merge conflict? no “git pull -f” doesn’t do it.

To do it really quickly, you can

git fetch
git reset --hard origin/master

To have closer control and do it file by file.

git pull
# assuming conflicts occur with style.css at this moment.
# this forces me to use the remote file. use --ours to use my version.
git checkout --theirs style.css
git add style.css
git commit

My experience with Magento, Woocommerce and other e-shop options


Magento has been a buzz word in the ecommerce industry for many years now. I worked with magento in my previous life and still get a lot of calls from many job agencies looking for magento developers today. The fact is that good magento developers are hard to find simply because having an in depth understanding of magento requires a bit of time. If you have good object oriented foundation, it  is not as complicated as many claimed. It was smooth sailing for me once I got the concept and the hang of it. The challenge for me was actually teaching the end user how to use it.

Magento was packed with features and was like out of the box. Most people only used probably 10% of what it had to offer. The large code base and number of objects also meant a strong requirement for hardware and server tweaks to get the desired performance. Caching helped but it was not enough. I was puzzled why most people opted for magento as their first choice when they wanted an e-shop. Perhaps this just showed how successful magento’s marketing was – they could brainwash the public into believing that magento was the best solution for everyone. I often warned people that unless they have lots (and I mean LOTS) of budget, magento should be the first thing they should strike from their list. Personally, I was not comfortable with the cost involved to get customisation in magento. You just need to look at the cost of some simple extensions to get a feel of what’s going on.

In conclusion, I was comfortable with the software but not comfortable with money making policy. My gut feeling was that they would face tougher competition from other ecommerce solutions as time went by (and I was right). Relunctantly, I filed a divorce with magento.

So go ahead with magento want a robust ecommerce solution and has too much money to spare.

Hosted solution

Most hosted solution such as shopify requires a monthly fee and is usually very user friendly. This can be a good option for people who requires little customisation and don’t want to host their own shopping cart. I never considered this as a good option for me because I always believed that personalisation and customisation was the key to improve client relationship. Hosted solution means limited customisation. The logic is simple, their software should be generic for everyone and they can’t break their software just to accomodate your requirements.

Woocommerce and Other Ecommerce Software

I have used other software over the years as well but came to like Woocommerce recently. Woocommerce offers the flexibility and robustness that an ecommerce shop should have. As it is open sourced (as with magento community edition), I had full control over the behaviour of the shop. There were enough hooks in the code to do what I want. I could also make it work with other wordpress plugins such as  membership management system, LMS, caching, seo…etc. The only thing I had to be careful was not to make the shop too bloated, ie by adding too much features into it, thereby affecting the performance.

I believe there are other good options out there and time will tell us when one stands out above the rest.

How to set wordpress default language

wordpress language settings can be configured in wp-config.php file (look for the WPLANG definition). The default language is en_US if not specified. So if you just bought a plugin and it only comes with en_GB, you might be wondering why the your content wasn’t translated…. You can either go into wp-config.php and set the WPLANG or you can rename the en_GB file to en_US.

Adding / Embedding signature with images in gmail

Creating a nice signature in gmail with graphics is cool but there are some tricks to get it to work. It is easy if you link the image source to some url, ie , <img src=””/>. To do that, design your signature in html and open it up locally in your browser. select the whole signature and copy it, then go to gmail -> settings -> general ->signature and paste your image in there. Unfortunately, you can’t type html in your gmail signature settings, else things would have been easier.

Embedding images in your signature instead of getting it from a http source is better because it doesn’t allow people to hotlink your image. To do that, go to gmail -> settings -> labs -> turn on canned response. Now create a base64 version of the images (just google around for some tools that you can use) used in the signature, your image tag will look like this <img src=”data:image/png;base64,iVBORw0KGgoAAAANSUhEUg…”/>. Again, design your signature in html and open up your signature your local browser, copy and paste the html in gmail. Send this mail to yourself. Now that you have receive this mail, forward it to yourself and you will get an option to create a new canned reponse from it. You have just created a signature template that you can insert in your mail in the future. Next time you reply a a mail, you will see a canned response option (a drop down icon on the lower right) for you to insert a saved signature, just insert the canned response after everything.

have fun.

H264 video encoding and transcoding using winff in ubuntu

winff is the gui version of ffmpeg (now superseded by avconv). Its the perfect tool to convert, resize and manipulate your video files.

Installing winff is easy, if using ubuntu/debian, just do a “apt-get install winff h264enc libav-tools” in command line.

Step 1: use avconv instead of ffmpeg

now I want to use avconv instead of ffmpeg. After opening up winff under applications/sound and video, go to edit/preferences/linux change the ffmpeg exec field to /usr/bin/avconv and ffplay exec field to /usr/bin/avplay

Step 2: Add new h264 profile

None of the current presets look good for h264 encoding. Under edit/presets, Add a new preset name under the websites category. In the preset command, enter

// refer to "man avconv" documentation on the options to use
-f mp4 -acodec copy -vcodec libx264

Step 3: now back to the main panel, select “websites” category and “h264” profile. Then change the video, audio…etc settings accordingly. Click on “Convert” and you will see a pop up terminal. The popup terminal provides tonnes of information on the video stats and debugging information should you wish to google for solutions.

I really hope there would be more documentation in this area rather than bits and pieces everywhere.

transmageddon is also good and simple linux video transcoder alternative but lacked the flexibility that winff has.

vimeo also provides some good compression chart.

Good luck.

Recommended bitrate for streaming videos

1000kbps for 360p (640 x 360px) seems to be spot on in most cases. vbr is preferred for http streaming, so it can be 750kbps – 1500kbps. we can still go higher for high motion videos. Many people use kush gauge as a rough guide..

Frame width * frame height * frame rate * motion rate (1,2 or 4) * constant (0.07)/1,000 = target bit rate in kilobits per second (kbps)

more information about kush gauge can be found here

Looks like the market doesn’t have any standard. Many enterprise businesses pump up their bitrate a bit higher to have better quality videos. We shouldn’t have disk space constraint. the only constraint is the user’s internet connection. The world’s average internet connection speed is 2300kbps (,15525.html) – a figure that you want to take note of when streaming videos.

good luck.

woocommerce: widget login redirect

If the woocommerce_login_widget_redirect hook doesn’t work, it is because the redirection occurs even earlier, in the core wp_signon function. so we need to hook on to wp_login instead, for example

// allow user to redirect to the same page from the place that they login. The exception is wp-login.php
add_action( 'wp_login', 'my_login_redirect', 2, 2 );
function my_login_redirect( $login, $user ) {
  if ($_SERVER['REQUEST_URI'] != '/wp-login.php') {
  // redirect to the referrer

put wordpress in maintenance mode quickly

while there may be nice wordpress plugins to put wordpress into maintenance mode, there is also a quick solution. WordPress is notorious for having bloated plugins that may slow down the site… so I love quick and less intrusive solutions.

Just create a an arbitrary file say .maintenance- under the wordpress installation dir. Put this code in the file:

$upgrading = time() - 1;

When doing maintenance, just rename the file to .maintenance and change it back to the arbitrary filename .maintenance- when done. That’s it.

If you want a custom maintenance page, create the page under /wp-content/maintenance.php

if you want to allow admin to access the site while others see the maintenance mode, use this code:

function is_user_logged_in() {
$loggedin = false;
foreach ( (array) $_COOKIE as $cookie => $value ) {
        if ( stristr($cookie, 'wordpress_logged_in_') )
            $loggedin = true;
    return $loggedin;
if ( ! stristr($_SERVER['REQUEST_URI'], '/wp-admin') && ! stristr($_SERVER['REQUEST_URI'], '/wp-login.php') && ! is_user_logged_in() )
    $upgrading = time();

When are we going to have a standard HTML5 format?

HTML5 drew a lot of attention when it first came out… embedding videos can be as simple as using a “video” tag.

However, thanks to the clash of video formats between patented and free codecs, web developers are faced with the same old IE + other browsers dilemma – they now need to create cross platform friendly videos. As a result, developers need to insert additional if-then-else javascripts to do the right thing for the right platform. The competition between apple (H264 codec) and Google (VP8) can be a good thing for themselves but its becoming too much politics for the rest of us.

It looks more and more like H264 is winning the battle. Is google going to concede or not? Why stand on the fence by supporting H264 in chrome? Even firefox finally conceded defeat this year. What does that mean for the consumer? How much more “if-then-else” are we going to have in our code and for how long?

Different browser support is already a headache. The codecs standardisation issue just adds salt to the wound.