Sun, 12 Apr 2015

Another year of Google Code Jam and interesting problems as always. I love how the problems end up looking simple at the end of each round.

Qualification Round

Standing Ovation

The first problem was relatively easier than the rest.

Your friend is an opera singer and you want to show her support by making sure everybody claps when she is done. This is determined by each person's level of shyness; you will only clap if n number of people clap where n is your shyness level (0 to 9). You can bring as many people as you want with any shyness levels you wish for to fill any gaps in the audience and en...

Sun, 11 May 2014

I have participated in this year's competition of  Google Code Jam. Being my first time in an online competition ever, it was pretty interesting, and tough!

The competition was as high as you can imagine, with people from all the different countries in the world, solving problems in minutes, problems that I would need at least an hour to solve. After getting disqualified today, I have realized I'm very slow when it comes to problem solving. I'm not sure if this is a bad thing though, it did serve me quite well when I used to work back in Zain, but it certainly didn't in an online competition.


Fri, 27 Dec 2013

One of the annoying things if you are behind a strict firewall is finding out certain ports are blocked to your server and you would need to stop everything you are doing until this is resolved. This is very common in corporates.

A useful and effective approach to this problem is using SSH to tunnel any port through an established SSH connection, it doesn't require you to enable these ports on your firewall, all you need is port 22.

The way this method works is by forwarding local ports to the destination ports on your server through your SSH connection. To your client, it's connecting to localhost, while i...

Sat, 07 Dec 2013

Compatible with:

Here is my setup for a production Ubuntu server running Nginx as a web server and uWSGI to wrap my Django project and execute python code.

You need to place your project somewhere, usually I create an OS user for my project and create a virtual environment in there. For this example:

Sat, 07 Dec 2013

After a couple of years of messing around with Django, I have settled with this project structure that I find to be verbose enough to remind me where everything is:

├── apps
│   ├── blog
│   ├── core
├── fabfile
├── frontend
│   ├── apps
│   │   ├── blog
│   │   ├── core
│   │   └── pages
│   └── libs
│       ├── bootstrap
│       │   ├── css
│       │   ├── fonts
│       │   └── js
│       ├── jquery
│       │   └── js
│       ├── prettify
│       │   ├── css
│       │   └── js
│       └── redactor
├── project
│   ├── env
│   │   ├──
│   │   └──
│   ├──...

Sat, 18 Aug 2012

For this website, I have a model called Category defined as follows:

class Category(models.Model):
    name = models.CharField(max_length=64)
    parent = models.ForeignKey('self', null=True, blank=True)

I wanted at some point to retrieve all the descendats of a certain category, unfortunately Django ORM doesn't have this feature out of the box (yet), so I had to create my own. The idea is create a recursive function that will collect a list of all the siblings at a certain depth and then move on to depth+1 until we get to the leaves.

def get_children(category):
    nodes = Category.objects.filter(par...

Sun, 12 Aug 2012

I have written a function in XQuery where you can pass a key as an argument and retrieve that key's value, this function can be applied on unformatted text.

I have defined separators (of pairs) as a regular expression pattern that would match all whitespace in addition to commas:

[ \t\r\n,]+

And then I applied another regular expression to extract the key and value parts out of each pair:


This pattern matches any alphanumeric keys (plus dots) and alphanumeric values (plus dots and dashes) that can be optionally quoted.

The full function is as foll...