Cherry-Picking for Fun and Profit

In Git, it is often useful to merge one specific commit from one branch into another. Frequently this happens when Using Git Interactive Rebase With Feature Branches, as you develop in the branch, you realize that one or more of your commits should be added to master right away, but not all the CLs. Enter git cherry-pick <changelist hash> for the win! The cherry pick command allows you to merge one CL from a branch, or even straight from the reflog into another branch.

Getting ready

For this article, lets assume you have a commit history that looks like:

fc64d55 -- d0e6ac9 -- 1edbe95 -- 24c685b -- 2f0514a  [master]
                         \
                          a70d41c -- b45af4a -- 38967f5 [branch feature1]

And we want to merge some important change in #b45af4a into master.

How do it…

The code to cherry pick the change into master is:

git checkout master
git cherry-pick b45af4a

Now rebase master on to the feature1 branch:

git checkout feature1
git rebase master

You may have to resolve conflicts, but notice that git is smart enough not to reapply the cherry picked changelist:

Applying: a70d41c
Applying: 38967f5

How it works…

It is important to note that cherry-pick behaves just like a merge. If there are merge conflicts that git cannot resolve, then it will ask you to manually resolve them. Consequently, the new changelist in master will not necessarily be identical to the cherry-picked CL, and it will definitely have a new hashcode. Fortunately, git tracks cherry-picked CLs, so when you rebase back onto the cherry-picked branch, it won’t duplicate the CLs and will restructure your history according to master.

Also, while cherry-pick is great for merging one or two commits, it is not ideal from many commits. If you need to copy

Gaming Engine - Snake Demo v2

Last week I was busy at GDC and have not had time to put together a detailed article, so in the spirit of GDC, I thought I would share the latest iteration of my HTML5 gaming engine (still very rough). There has been a lot of progress around the Game class to support stages (or levels) and a score board to track the player’s score. The stages are demoed by a new version ...

Use && Instead of Semicolon to Separate Commands

Today’s article will be short and will cover a bash topic that frustrates me to no end. Please don’t use ; to separate commands, when you mean &&. There is an important difference between the two and many developers never realize that they want to be using && in their scripts.

How do it…

Here is a common oneliner that you might use to compile a package:
 ./configure ; make ; make ...

Using Promises to Cache Static AJAX JSON Data

This article showcases a useful caching strategy for static data that is fetch via AJAX. We will use jQuery to setup a promise and cache the data in the localStorage for subsequent page loads or data loads.

Getting ready

A modern web browser supporting localStorage and JSON. Also, a basic understanding of promises[2] is helpful.

How do it…

Here is the code:
 (function($) { var oKeyDeferredMap = {}; function fnReadData(sKey) ...

Joined Google Play Games

I must apologize for the dearth of articles these last couple of weeks. As some of you know, I recently joined Google and there is a lot of technology to come up to speed on. Specifically, I have joined the Google Play Games team, which is a core service of the android operating system. We provide APIs to help game developers build better games with less work, and I am super excited to ...

Connecting to Github and EC2 Through a Proxy on Port 80 or 443

Today we’ll cover how to connect to github and EC2 through a draconian proxy allowing only port 80 and 443. Github uses SSH, so like EC2 it can be connected to using SSH tunnelling. This article is based on a blog post by tachang[1], which needed some additional explanation and changes to work behind my proxy. I will be explaining how to connect on a unix-based machine, but these settings should also work on ...

Introducing Gaming Engine - Snake Demo v1

In my not so copious spare time over the past few months, I’ve been working on a game engine to power two dimensional board-based games. The engine has a long way to go, but I have reach the first demo milestone and wanted to share it with you. Here is a basic version the snake game written using the game engine. It illustrates a working main thread, responsiveness to keyboard commands, interaction between a ...

jQuery Function for Change Event and Delayed Keydown Event

In my experience, it is rare to assign only a change event to a text input, as any callback that would be executed for the change event should also be called on a key event as well, but with a slight delay (think how an autocomplete shows results as you type). This is a common pattern and I was surprised to not immediately find a jQuery plugin implementing it, so I decided to add one ...

Merge Sort

Continuing to evaluate efficient sorting algorithms, today we’ll look at merge sort. Merge sort[1] is a comparison sort using a divide and conquer algorithm, developed by John von Neumann[2] in 1945. It recursively divides the list into smaller sublists of length one, then repeatedly merges the sublists in order until there is only one sublist left. It has a worst case runtime of (O(nlogn)), making it worst-case more efficient than Quicksort.

Quicksort

We’ve looked a variety of in-efficient sorting algorithms, today we’ll look at Quicksort (aka. partition exchange sort), as a first foray into faster and more frequently used sorting algorithms. Quicksort[1] is a comparison sort using a divide and conquer algorithm, developed by Tony Hoare[2] in 1960. It recursively divides the list into smaller lists around a pivot value and sorts them, which means much smaller data sets when actually sorting. It has a ...