-
In the celebration of 10M questions on StackOverflow
Who among us developers doesn’t know StackOverflow? If you don’t know it then there is a big chance you didn’t search for any programming related question in the last 7 years, so you either are doing a super great job, using a super old community of old school programmers, or actually didn’t practice programming for some really long time.
StackOverflow reached more than 10 million questions, I won’t list those amazing numbers and statistics here, feel free to see them on StackOverflow’s 10M page, they are really great to read and to try to imagine them.
I’m not going to talk about its history, the internet is full of those articles, you can read about it from Wikipedia or from its co-founder Joel Spolsky. I will talk about my story and how I see StackOverflow in this occasion, it’s my way of celebrating the success of this global platform, and the success of humanity there.
Read more… -
Verifying User Input – Thinking Outside The Box
Now I’m not going to talk about user input validation, no that’s something that’s been covered a lot around the web, I’m going to talk about something else.
Let’s imagine you are designing a game, where the user can create a puzzle, for example a maze, and you want to verify that what the user has input is a valid maze, that if played by another player that player will have a chance of winning it. Normally the solution that would come to your (and mine) mind is to try to solve that maze automatically – also we’re not going to talk about the different algorithms for solving mazes – but there is another way to do it that no one told us about in Algorithms 101!
Read more… -
Using curl with Proxy PAC configuration files
curl is an essential tool that most developers use, it will allow you to execute a wide range of HTTP requests from your terminal, it supports using a proxy to execute your requests, but it does not support PAC configuration files.
At my work I have to use a PAC file due to the large list of servers I’d interact with, and many would require me passing through specific proxies. It is a cumbersome process for me to memorize or try every URL I want to request and to identify which proxy to use, that’s why I wrote a simple perl script (yes perl not Python!) to help me with this issue.
Read more… -
Joining Booking.com
After spending 3 years in Dubai and working at 2 different startups there, and after having worked at 5 different startups since I started working, I decided it’s time for me to move up and faraway from Dubai and startups, I started looking for jobs at big companies, Google, Facebook, Twitter, and got into a couple of interviews, and in the end I chose to go with Booking.com and I will be joining their team starting December 2014 as an IT Developer!
Read more… -
Django Country Context
This module solves a small problem that can be found in many sites, where the website has to support multiple countries, e.g. e-commerce website with different stores for different countries, this module allows the developer to define a context per thread, this context holds all the information about the currently available country, and allows the developer to rely on the context always to get the current country instead of passing it through the different levels of code. This module is thread-safe, it defines a different context for each thread.
Read more… -
How to make django management commands send errors email to admins
I usually use django’s custom management commands to do different tasks on the web application, most of the times with a cron job running those commands. The problem is that when you’re using a cron job, you won’t get the beautiful django error email when something goes wrong.
Read more… -
How to make logrotate use SSMTP
A few days ago I was looking at my server logs, my website logs are more than a year old and growing, so I was reading some of them and wanted to download the old logs, truncate the logs, so that next time I read the logs I won’t have to look at very old data. So basically I wanted to rotate the logs and archive them, luckily logrotate is there to let me manage and administer log files in my system. It has a long list of features with a very easy configuration, so it was the tool I’m looking for.
Read more… -
Adding a timestamp to command output in linux
This is just a quick solution to put a timestamp with each line of the output of some command in Linux (*nix). It’s a very simple thing, thought I’d write it down here so maybe it’ll help somebody some day.
I have a cron job running on my server, it’s a high frequency job so I don’t want to send email reports each time, I’m logging it into a file, but I want to log the timestamp of each time it runs and logs something to this file, I didn’t want to change the code behind it to also print the timestamp with each write to the output, so I pipelined the command to a simple bash script that will append the timestamp to each line in the output then write the result to the stdout again.
Read more… -
Get Pattern From an Image in PIL Python
Two days ago I needed to generate a PIL image that is made up from repeating a pattern – another PIL image – multiple times, I didn’t find a code online to do it so I just wrote this small code to do it, thought might share it to help somebody out there.
Read more… -
Python Celery Asynchronous Task Decorator
A while ago I was working on a project in Django that had many tasks that needed to be executed asynchronously such as sending emails, generating reports, and checking some database related issues.
Executing asynchronous tasks in Python can be made in multiple ways, one of them is using celery, a distributed task queue written in Python which has proved itself to be a great solid task queue system.
And if you’re using Django then there is a Django app to make your life easier, django-celery.
Now as always I like to make my own life easier also by implementing generic solutions for my needs, so I have written this simple piece of code to create a function decorator that declares the function as an asynchronous task, which means that by just adding this decorator to the function it becomes asynchronous.
Read more…