Moazzam's Ramblings


My mechanical keyboard

In my last post, I talked about mechanical keyboards and how great they are to type on. I figured I would show you guys what my keyboard looked like. I have a Corsair K60 with custom key caps (well some of them are custom). Corsair did a great job with the keyboard and the only thing I didn't like about this keyboard is that the right shift wasn't smooth to press if I were to press it on the edge. I, accidentally, solved this problem by changing the keycaps. So here is what my keyboard looks like:

Filed under: Uncategorized No Comments

Mechanical keyboards

Between work and personal projects, programmers tend to type 8 or more hours a day and it helps to have a keyboard you can type on comfortably. Something that wont kill your fingers or your hands over time. Mechanical keyboards fill this need. They have taken the gaming world by a storm and a lot of the hard core programmers I know don't like using anything else. Now that more and more companies have started to offer mechanical keyboards as part of their lineup, it is really easy to get your hands on one.

For those who don't know what mechanical keyboards are, you can read about them here: I got interested in them because my Dell keyboard (the one that comes free when you buy a PC) was starting to feel like I had to fight it to type anything. This made me start looking for an alternative. The first mechanical keyboard I tried was a DAS keyboard and now I don't ever want to use a rubber dome keyboard ever again (except Kinesis freestyle 2).

Mechanical keyboards are a treat to type on and come in many shapes and sizes. If your fingers hurt when you type on a regular keyboard I highly recommend that you get a mechanical one. You don't have to press the keys all the way to the bottom for the computer to know you pressed a key. This means your fingers face less resistance when typing. You will, however, have to practice not bottoming-out the keys (pressing the keys all the way to the bottom).

If this has made interested in mechanical keyboards and you want to get one. Here are some I recommend looking into:

  • Filco Ninja or Majestouch 2 keyboards. Filco is, hands down, the best keyboard maker. Their keyboards are not backlit and don't have macro support but their build quality is the best. Amazon is the only reseller that sells these in USA.
  • Ducky Shine. Ducky is more of the higher end mechanical keyboards and they have the best backlit keyboards.
  • DAS keyboard. DAS has been making keyboards for quite some time now and I love their design. Their keyboards, like Filco, are also not backlit
  • Ergodox. This is an open source keyboard you will have to make yourself but it is very ergonomic and you get the satisfaction of having made your own keyboard.
  • Fully mechanical keyboards by Corsair. Corsair has some very original designs for their keyboards. Their keyboards have no bezel making it really easy to clean them. Starting from K70, they are backlit.
  • Filed under: Uncategorized No Comments

Corsair k60 OSX issues

I got a Corsair K60 a few months ago and fell in love with it. It is a mechanical keyboard (my first mechanical keyboard) with Cherry MX red switches. There is, however, one problem with it. The caps lock LED is always on and the LEDs for num lock and scroll lock are always off.

This affects all models of Corsair keyboards as far as I know. Why they don't just add support for Macs? I don't know. It can't hurt. It is just another HID device.

The keyboard will toggle caps lock when you press it but it won't change the state of the LED. So, like any sensible person I set out to fix the damn LEDs. And, let me tell you it was not an easy task (considering I have not programmed a single line in objective C before this or written any hardware drivers in any language).

After spending the whole weekend on it, I was able to write a program that will listen for key strokes from k60. Now, I have to figure out how to toggle the LED when caps lock is pressed and I will be able to have a normal functioning keyboard.


You can make PHP extensions in a PHP like language

I recently came across an article which spoke about a language called Zephir. It was written with the goal of letting PHP programmers write PHP extensions. I was really happy to read this. For quite some time I have dreamed of creating PHP extensions but the fact that I would have to learn C kept me away from it (although I would have eventually done it). And, I have been jealous of Lisp which can be extended using Lisp itself (unlike PHP which requires you to know C to extend it)

Zephir looks almost like PHP. There are a few differences but if you are a PHP developer it will probably take you mere hours to get the hang of it. The same guys who wrote the Phalcon framework have written Zephir. For those of you who don't know what Phalcon is, it is a framework written as an extension of PHP. It is the only framework of its kind (as far as I know). All other frameworks are written in PHP.

Imagine the speed boost something like this can give your application. Binary code executes much faster than interpreted code. You can shift all your intense computing code to an extension and improve the performance of your application by quite a bit.

You can learn more about Zephir here:

Filed under: PHP No Comments

Technology is a means to an end and not the end itself

Last Friday, the CEO of the company I work for said something interesting: "Technology is not the end. It is a means to an end." He, then, elaborated that by saying that we are making applications to make people's lives easier. The code doesn't have to be perfect. If it works for 90-95% of the cases, it is fine. We can go back to it later and refine it.

This caused an internal debate within me. I have always been (and still am) an advocate of beautiful code but I have (occasionally) let myself get slowed by trying to make code more beautiful (and better organized). What I should have done is made something work then refactored it afterwards. This way, I don't delay a release and I get time to make things better later.

Obviously, this assumes I will get time later on to make the code better organized or more understandable. Depending on the industry you are working in, you may not have the time to make things better or refactor the code. So how does one deal with this? You have to strike a balance (which may not be easy at times) between trying to make everything 100% perfect and finishing the project on time.

I don't want anyone to think that it is okay to write sloppy code and use this reason an excuse. I have had to deal with the aftermath of such code way too many times. Let me tell you, it is not pleasant (although sometimes it can be interesting). It is, however, important that we don't get bogged down by writing that perfect piece of code that we lose sight of what is most important - getting the application in the hands of the end-users who will have feedback of their own.

Filed under: Uncategorized No Comments

Selenium Chrome driver nuances

When writing test, you generally tend to run the test in one browser and expect it to work on all the rest (except maybe Internet Explorer). I had ran my tests on Firefox and they succeeded but not on Chrome.

In Firefox, if you click on an element that is not currently visible on the screen, the browser will click allow it and not cause any issues. However, Chrome will complain saying that the click will be caught by another element (depending on how you structured your HTML). So, you have to move to the element before you can click on it.


Testing multiple browsers with Selenium2 in PHPUnit

You used to be able to run test on multiple browsers with PHPUnit Selenium test class by specifying a $browsers property. You can still do the same with PHPUnit's Selenium 2 class made for web driver. Here is how you do it:

class SomeTest extends PHPUnit_Extensions_Selenium2TestCase
	 * Variable to specify which browsers to run the tests on
	 * @var array
	public static $browsers = [
		['browserName' => 'firefox'],
		['browserName' => 'chrome']	
	public funciton __construct()
	public function setUp()
	 * This is just a test that will open a website in chrome and firefox
	public function testOpenSite()

Fastest way to traverse an associative array

PHP has array_walk() which can be used to traverse an array and modify it in place. I wanted to find out if array_walk() would be faster than a loop written in PHP (for, foreach). I mean, PHP's code is written in C/C++ and traversing anything has to be faster in C than in PHP.

So, I wrote a script to traverse an array of about 100,000 elements. Below are the results (formatted for better readability):

new-host-2:exp moz$ php for.php
Method          Time taken to traverse 100,000 elements
for		0.030004024505615
foreach		0.0066280364990234
array_walk	0.019280910491943
new-host-2:exp moz$ php for.php
Method          Time taken to traverse 100,000 elements
for		0.041378974914551
foreach		0.0075538158416748
array_walk	0.02002215385437
new-host-2:exp moz$ php for.php
Method          Time taken to traverse 100,000 elements
for		0.029618978500366
foreach		0.0064899921417236
array_walk	0.018718957901001
new-host-2:exp moz$ php for.php
Method          Time taken to traverse 100,000 elements
for		0.041105985641479
foreach		0.007500171661377
array_walk	0.020205974578857

foreach traverses an associative array faster than array_walk() and for loop. In fact, it was much faster than both. I had expected array_walk to be faster but I was wrong. You will notice that the while loop isnt in there. I figured that a while loop would take about the same time as a for loop. Here is the script I ran for my experiment:

echo 'Method          Time taken to traverse 100,000 elements', PHP_EOL,
     . '========================================================' . PHP_EOL;
$assocArray = [];
for ($i=0; $i < 100000; ++$i) {
	$assocArray['key' . $i] = 'hi ' . $i;
// Let's begin the tests
$keys = array_keys($assocArray);
for ($i=0, $n=count($keys); $i<$n; ++$i) {
	$tmp = $assocArray[$keys[$i]];
foreach ($assocArray as $key => $val) {
	$tmp = $val;
array_walk($assocArray, function ($item, $key) {
	$tmp = $item;	
class Timer
	protected static $start;
	protected static $stop;
	public static function start()
		self::$start = microtime(true);
	public static function stop()
		self::$stop = microtime(true);
	public static function diff($label)
		print $label . "\t\t" . (self::$stop - self::$start) . PHP_EOL;
Tagged as: No Comments

OSX Mavericks upgrade and PhpStorm problems

I upgraded my work laptop's OS to Mavericks (finally). Started the upgrade yesterday when going home and when I went back to work today, PhpStorm stopped working. I got no errors, no warnings, nothing. It didn't even give me an indication stating that it was trying to open PhpStorm.

So, like any sensible person I tried opening it through the command line and that's when I got this error:

LSOpenURLsWithRole() failed with error -10658 for the file /Applications/

So, I tried to run the executable for PhpStorm directly like so:


It told me Java runtime is missing and it is requesting that it be installed. After that, if you cycle through the windows you should see an alert asking you if you want to install Java 6. Hit yes, and you should be good to go.

If you don't see the alert, restart your machine and you will see it as soon as you login. Or, you can also just go to sun's website and install it.


Is OSX the best Linux

Someone I know mentioned in passing that OSX is the best Linux out there and I have been thinking about it ever since.

A lot of developers I know get MacBooks to work on (and not Linux desktops or laptops) for multiple reasons. The business has a point of support they can pester if anything goes wrong with the machine or its software. And, the laptop can be used by people who are not very knowledgeable about how their operating system is doing the things it is supposed to do - like designers. I didn’t know this but most really good designers use Apple machines.

Linux operating systems (for the most part) demand you know what you are doing. It is not for meant for the people who don’t want to know how their operating system is doing what it is supposed to. Ubuntu, however, has done a great job of trying to make it user-friendly. They, now, have an App Store like application which you can use to install games, applications, etc and buy them. I haven’t played much with it but it looks promising.

I had tried installing a Linux (don’t remember if it was Fedora, Ubuntu or something else) on a laptop and that was a nightmare. I could not get the wireless adapter to work. I had to scour the internet for days before I found a solution to my problem. While it was a tad annoying to have to go through all that trouble to just get a wireless adapter to work, it was interesting to see how things worked. However, that will not fly in an environment where I just want to get things done.

It is (in general) easier and more pleasant to work on a Mac than it is to work on (let’s say) Ubuntu. I am not saying it is always the operating system’s fault. The applications written for Linux are sometimes sub-par for a regular user. My experience with Dota 2 on Linux is a great example of this. It was un-playable on Linux and I had no problems with it on OSX. Valve has since updated the code and made the Linux experience more pleasant but it is still not as good as Windows or OSX.

I love Linux. If you have an old machine you can bring it back to life by installing a minimalistic flavor of Linux and get it working again. Servers built on Linux are so stable that it’s not even funny. One of my employers had both Windows and Linux servers. The system administration team would always complain that Windows servers crashed almost every week while Linux servers didn’t need to be touched at all. I love the fact that there is so many free applications available on Linux that are better than commercial applications available for the same. Penetration testing tools are a great example of this.

So, it depends on the context. For regular use OSX is definitely better but for servers and hardcore bad-assary of installing an OS on a small board in a motor-cycle because it has such a low footprint and then using that as a mobile cam just because you can. Nothing beats a regular Linux OS (Slackware anyone?).

Filed under: Uncategorized No Comments