Coffee Coder

Shubham Jain's Weblog

Hackers Are the Real 10x Engineers.

| Comments

The notion of 10x programmer was first mentioned by John Brooks (of, Brook’s law fame) in his essay No Silver Bullet, according to which, ‘there is as much as a tenfold difference between an ordinary designer (programmer) and a great one’. The idea has been widely debated, sometimes refuted and many times defended which is unsurprising for it is impossible to accurately measure a programmer’s productivity.

Sadly, the idea of 10x coder is usually visualized as a screen glued junkie, moving fingers over keyboard without a break. While the picture may be popular for sci-fi films, it is hardly close to reality.

My Perfect Reason to Avoid PHP: Type Juggling

| Comments

If there was an award for the most hated language, the unanimous winner would be PHP. Lots of write-ups criticize it for its nonsensical function naming conventions, inconsistent parameters, sheer absence of what we call, “a well thought design”. However, people on the other side, suggest that writing good code is upto the programmer showcasing “Zend Framework”, they assert, PHP is a very reasonable language to write clean code. They say its easy to ignore the inconsistencies with a good editor or IDE and adopting good practices. True they are, I believed, until, I encountered something which is completely inexcusable, an ugly case of type juggling.

Type Juggling

Type Juggling (or, automatic type casting) is a PHP mechanism which transforms one type to another depending upon the context. As the manual explains, if you add a string to a number, the string will be type casted to a number and not the other way round which results in something like this.

20 + "10Hello World" = 30

Why Should You Use Tmux?

| Comments

Terminals are an essential place frequented by developers in their daily use. In contrast to GUIs, command line gives you more folds of power and transparency when you dealing with a complicated tool like git, or when you need to pull off some networking stats using netstat. In this blog post, I’ll explain why tmux is a great productivity enhancer when working with command line.

What is tmux?

tmux or terminal multiplexer is a simpler version of GNU screen, both of which are tools to split, combine and create terminal windows. Yes, that is indeed similar to what terminator does but guess what, you can’t run terminator on SSH, can you? but that is not the selling point here. tmux is command line based tool which is very easy to use and in fact for any beginner, a little primer should be enough to start using it to its full extent.

Using Git for Introducing Temporary Changes

| Comments

Lately, on independence day we needed to introduce a small logo change on our website to acknowledge it. The change wasn’t meant to last for more than a few days and hence, the problem of introducing a temporary change which shouldn’t be a part of the history arose. Out of ignorance, we went through the path of making a commit and later reverting it with git-revert. Recently I found about excellent patching system of git which makes an impressive solution for the problem.


Patching used in git isn’t unique. It derives itself from an old patch program written by Larry Wall in 1985. patch program is pretty simple. It takes a diff file as its input and applies those changes to corresponding files. Because of this simplicity, it makes patch files very easy to send. Perhaps, before the advent of github, they were the old man’s pull request. Another great thing about patches is that they can painlessly be reversed.

Git’s format-patch is an extension of patch and offers two advantages over it. First, it generates an email formatted patch file which is much easier to be sent via mailutils. Secondly, it supports binary diffs which means if you have a binary file which was created in the patch, git’s patch file will have record of it and it will be created when patch is applied. The best thing about git’s patching system is that it can be applied even if the folder is not a git repository, making it suitable for use over production servers.

Building a Whistle Detector Using WebAudio API

| Comments

There are lots of things to get excited about HTML5 and the one which caught my curiosity was HTML5 Audio / Video API. I was overwhelmed with ideas of practical applications like face detect login or inline dictation but I chose to start with something small – a whistle detector. Although, not wholly accurate it works quite well with very a good accuracy. I used M. Nilsson’s research paper, “Human Whistle Detection and Frequency Estimation” to implement this. It took me a while to get understand exactly what the paper narrates with its mathematical notations but luckily my wandered at the right place to get the right idea.

For the first part, I would try to explain Successive Mean Quantization Transform (SMQT) which prepares the audio data for further processing.

Successive Mean Quantization Transform

Transformation in mathematics is an operation to map one set to another set. SMQT is a similar method to do the same to remove bias or gain resulting from disparity between various kinds of sensors (microphones) and other factors. In SMQT, we recursively take mean of data set and split it into two halves and do the same on each half. Data values above the mean are assigned, “1” and below are assigned “0”. The recursion is carried out to a pre-defined depth, at the end of which we have a binary tree with 1s and 0s. Sounds confusing? Lets take and example of set:

X = [89, 78, 63, 202, 90, 45, 112, 79, 95, 87, 90, 78, 54, 34, 66, 32].

Mean(X) = 80.875

The values above mean are assigned “1” while below are assigned “0”. So it becomes – [1 0 0 1 1 0 1 0 1 1 1 0 0 0 0 0]. Let this procedure be called as U(X). Data values corresponding to “0” propagate left of the binary tree while “1” propagate right. So we have a tree which looks like,

Continue this process recursively till you reach a depth of L. ( Note: L = 8 in our application. )

After this, you weight each level by multiplying the bits by 2cur_level – 1 and add it up to the top of tree. So, if you have a tree which looks like,

Multiply D, E, F, G by 22 which gives [4 0 4 0], [0 0 4 0], [0 0 4 4], [4 0 0 0] and so on. Lets call this procedure of weighing individual arrays as W(X). After we are done weighing, we add to the node its subtrees. For eg, B = W(B) + (W(D) . W(E)). So we have now have audio data that is bias and gain free. (Gist).