Desi Founder @ work http://www.sharjeel.2scomplement.com Sharjeel Ahmed Qureshi posterous.com Tue, 08 Nov 2011 12:53:00 -0800 Visual Complexity of MS Windows http://www.sharjeel.2scomplement.com/visual-complexity-of-ms-windows http://www.sharjeel.2scomplement.com/visual-complexity-of-ms-windows

Over the years, Microsoft has evolved Windows into a very mature Operating System. I've found Windows 7 pretty stable and many people agree with that. However one thing I feel Microsoft hasn't got it right is the default window decoration.

Take a look at the two Command Prompt windows overlapping each other:

Untitled

The one in the rear is using Classic Windows decoration which is similar to that of Windows 2000. The one in the foreground is using the new Window decoration introduced in Vista and is considered to be better by Microsoft and hence set as the default one. It also uses Aero effects to reflect state of background windows into current's top bar and borders.

Most people find the former a bit boring but at the same time less distracting, simpler, visually easy to follow and hence practically better in terms of user experience.

The latter adds some bells and whistles by extra colors, more shades, thicker and blended colored borders, semi transparent windows.

Now let's analyze the two:

Untitled2

Clearly, the new interface has many extra things which are not part of the content of the Window but are added just as "effects". However they require cognitive efforts to separate from the actual meaningful content.

In 99.9% of the cases I really don't want to see through my current windows to look at the blurred view of the Windows underneath; it just required my brain's processing power to figure out the current window's contents and separate them from the window underneath. Also, such a thick border doesn't contribute into anything positive in terms of User Experience.


On the other hand, let us compare equal sized windows of Windows Messenger and Google Talk. Windows Messenger uses default window decoration while Google Talk uses a much much simpler user interface.

Window-msn-gtalk

In the above screenshot, Windows Messenger is not showing me a single meaningful thing in terms of an Instant Messaging service. On the other hand, with the same window size, Google Talk is delivering everything: my online friends, away friends, statuses, search box, unread emails. I can instantly click on a friend and start chatting. I can't do that in Windows Messenger without resizing the Window to something much bigger. That is because not much thoughts have been given to space utilization.

Microsoft is simply not learning one simple thing: more is less and less is more.

I hope one day Microsoft's UX/UI teams will try to utilize every pixel into something rather than just bloating up everything. And they must start with the default window decoration.


Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/missing-user-75.png http://posterous.com/users/Q9gllRLHXz Sharjeel Ahmed Qureshi Sharjeel Sharjeel Ahmed Qureshi
Thu, 06 Oct 2011 00:18:15 -0700 RIP Steve Jobs http://www.sharjeel.2scomplement.com/rip-steve-jobs http://www.sharjeel.2scomplement.com/rip-steve-jobs I am sad to learn that the man who brought beauty into Computing passed away today. Steve Jobs was an artist. His artwork has made the experience of interacting with computers aesthetically pleasing and joyful. Only Steve could have done it! He will be long remembered!

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/missing-user-75.png http://posterous.com/users/Q9gllRLHXz Sharjeel Ahmed Qureshi Sharjeel Sharjeel Ahmed Qureshi
Tue, 12 Jul 2011 12:33:17 -0700 Quick backup of delicious bookmarks http://www.sharjeel.2scomplement.com/quick-backup-of-delicious-bookmarks http://www.sharjeel.2scomplement.com/quick-backup-of-delicious-bookmarks Since delicious's new owners are going to be making some changes in the bookmarks, it is a good idea to take a backup of your bookmarks.

The quickest is simplest way is to use the delicous's API. Just log into delicous the open the page:

https://api.del.icio.us/v1/posts/all

This API link provides you all your bookmarks in XML format. You can save the link and process the XML file however you like. Easy, isn't it?

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/missing-user-75.png http://posterous.com/users/Q9gllRLHXz Sharjeel Ahmed Qureshi Sharjeel Sharjeel Ahmed Qureshi
Sun, 19 Jun 2011 10:49:37 -0700 Slow Rails/WEBRick server inside VirtualBox http://www.sharjeel.2scomplement.com/slow-railswebrick-server-inside-virtualbox http://www.sharjeel.2scomplement.com/slow-railswebrick-server-inside-virtualbox While trying to play around with Rails running in a VirtualBox and accessing it from my host Windows OS, I found it to be painfully slow. I'd heard that Rails is slow but surely not slow enough to respond to a simple request in over a minute.

The problem is that WEBRick, the default development server for Rails 3.x, can be problematic with remote requests. The problem is caused by Reverse Lookups by the web server which cause the server to respond only after the lokups fails by timing out,

This can be fixed by replacing the following line in WEBrick's config.rb:

:DoNotReverseLookup => nil,

with:

:DoNotReverseLookup => true,

With normal installations config.rb can be found in /usr/lib/ruby/<version>/webrick/config.rb, or if you are using rvm, it'll be in ~/rvm/rubies/ruby-<version>/lib/ruby/1.9.1/webrick/.

This now makes the requests served almost instantly rather than make you wait till death by frustration.

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/missing-user-75.png http://posterous.com/users/Q9gllRLHXz Sharjeel Ahmed Qureshi Sharjeel Sharjeel Ahmed Qureshi
Tue, 12 Apr 2011 16:04:00 -0700 SQL Injection Honeypot http://www.sharjeel.2scomplement.com/sql-injection-honeypots http://www.sharjeel.2scomplement.com/sql-injection-honeypots

One way to prevent hackers from finding vulnerabilities on your website is to keep them busy with fake ones. For instance few years ago when I was graduating in my undergrad programme, I developed a web based application to faciliate the data collection and publishing of my batch's Yearbook. The application provided the users interface to complete their profiles, write comments about their friends and upload photographs, of course after logging in.

The login procedure was much like any other site: user authenticated themselves using username and password which were matched from the database. However, if there was a single-quote in the user's provided username or password, the system gave an error message showing a query string which failed to execute. Not that it was a SQL injection vulnerability, I'd the message intentionally to see how people react after finding a potential vulnerabilty. Of course it only showed the message and didn't give the user any extra access.

Here is a code snippet of the authentication module:

    // SQL Injection 'TEST'
    if( strpos($username,"'") !== false || strpos($password,"'") !== false )
    {
        $sqlInjectionError = "
                <p><font size=2>Microsoft ODBC MySQL Drivers Message:</font></p>
                <p><B>Error in the query:</B></p>
                <p>[Microsoft:ODBC 1045] SELECT UlluKaPatha FROM UlluKePathay WHERE GadhayKaRollNo = '".$_POST['username']."' AND GadhayKaPassword = '".$_POST['password']."'
                ";
    }
    // End SQL Injection 'TEST'

e.g. if someone provided username admin and password x' OR '1'='1, he she got the response:

Microsoft ODBC MySQL Drivers Message:

Error in the query: [Microsoft:ODBC 1045] SELECT UlluKaPatha FROM UlluKePathay WHERE GadhayKaRollNo = 'admin' AND GadhayKaPassword = 'x' OR '1'='1'

I'd initially included it as humor but later found out that some of my fellows didn't get the joke and started getting excited about the "vulnerability". They got challenged and tried all sorts of SQL injection attacks. I started logging those breaking in attempts and found some further clever techniques being applied I wasn't aware of before. This simple snippet served as a HoneyPot, attracting hackers and giving away some important information as to what they are trying to do and what different techniques they apply once they see some potential as well as diverted their attention away from find some other subtle vulnerabilties which actually existed.

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/missing-user-75.png http://posterous.com/users/Q9gllRLHXz Sharjeel Ahmed Qureshi Sharjeel Sharjeel Ahmed Qureshi
Thu, 06 Jan 2011 11:20:00 -0800 PyLint - A simple but important tool for Python programmers http://www.sharjeel.2scomplement.com/pylint-a-simple-but-important-tool-for-python http://www.sharjeel.2scomplement.com/pylint-a-simple-but-important-tool-for-python

The weak typed languages, such as Ruby and Python, give you a lot of freedom by not enforcing you to explicitly declare variable names and their types. The good part is that you stay focused at the problem at hand by using the variable when you want rather than going into the fine details of the language. When you want to use a variable, just use it rather than going up in your code declaring the variable and coming back and re-thinking where you were in terms of the algorithm.


The downside of weak typing is that you can easily shoot yourself in the foot. Since everything is evaluated at run-time, your program will run smoothly until the problematic part of the code is executed. On the other hand, static typed languages such as C/C++ and Java prevent you from shooting yourself by enforcing you to specify the names of the variables you are going to use in a particular scope and their types. The compiler makes sure you haven't incorrectly used a variable and won't compile your program until you have fixed all of your errors. It can also warn you about the potential problems.

For instance, you use a variable named "colour" and few lines down you refer it as "color"; C++ or Java's compilers will catch it before the program is compiled and run. But if you run such Python code right away, you won't be that lucky. And if that piece of code is likely going to be run in a rare scenario, the problem might appear only at the production level.

However, using a code analyzer it is possible to detect many of the problems in weak typed languages without actually executing the code. The code analyzers can detect incorrect variable names, potential incorrect typing, warnings and coding style relating problems.

For Python, my choice of code analysis is PyLint. It is a simple and easy to use tool which quickly efficiently performs code analysis, finds bad smells in your code and can format the output neatly into a form of your choice. It also integrates well with different IDEs.

Installion

Installing PyLint is pretty simple. First install setuptools (http://pypi.python.org/pypi/setuptools#files). Then on command prompt run "easy_install pylint". If you are using Windows 7 or Windows Vista, make sure you open the command prompt in Administrator Mode.

Usage

You can run PyLint by calling the lint.py script which is usually placed in the Python's site-packages directory.

> python c:\Python26\Lib\site-packages\pylint-0.22.0-py2.6.egg\pylint\lint.py test.py

It is a good idea to make a batch file and pylint.bat file to avoid typing all of that.

You can also specify command line parameters to pylint to control the output format and verbosity. There are numerous parameters but you'll probably need a few of them: the format option (-f) and Errors Only mode (-E).

The -f specifies the format options. Choices are text, parseable, msvs and html. Depending upon the choice of -f parameter, pylint outputs its results on stdout in the specified format. Parseable format can be used by IDEs to format the lines and integrate it with their editor so that you may click on a message and the IDE will take you to the correspondinvg line. HTML is useful in case of version control systems which display their outputs in browsers. For instance you can configure your SVN to run PyLint on each commit and output will be displayed in a browser.

Add -E in options to change mode to errors-only. This is effectively the verbosity level of PyLint and will report only the errors, skipping the coding style problems and other warnings.

Integration with PyScripter

Integration with PyScripter IDE is pretty simple. Just install PyLint and run PyScripter. Press CTRL + L and output of pylint for your code will appear in the list in the messages window pane. Clicking on a message from the list will take you to the correponding line in the editor

Pysccripter-pyling-1

To see only the error messages and hide coding style and other related warnings, goto Tools -> Configure Tools -> Py&lint and append -E in Parameters. Now when you'll run Pylint, you'll only see errors.
Pyscripter-output-2

Pylint is an extremely important useful tool to use. It should be regularly used especially before committing your code to make sure you don't miss out anything. However you shouldn't completely rely on it as all code analyzers have their limitations.

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/missing-user-75.png http://posterous.com/users/Q9gllRLHXz Sharjeel Ahmed Qureshi Sharjeel Sharjeel Ahmed Qureshi
Wed, 27 Oct 2010 06:01:03 -0700 Network throttling tools http://www.sharjeel.2scomplement.com/network-throttling-tools http://www.sharjeel.2scomplement.com/network-throttling-tools There are scenarios when you'd want to throttle your connection to simulate inferior connectivity. For instance you'd like to see how your application is going to behave when working with a slow network connection. There are complex methods available but I found some simpler ways to achieve this:

For applications running on some standard protocol such as HTTP you can easily introduce a proxy such as squid to control the rate of traffic. At a higher level, it becomes even simpler in browsers with plugins such as Firefox Throttle and IE Throttle.

However if you want to test a standalone application in which it is not possible to introduce a proxy, you can throttle the network traffic at the lower layer of the network stack.

In Linux, it is possible to introduce throttling at interface level using traffic shaping. You can write traffic shaping rules to control the traffic; however I've found those rules a bit complex. There are scripts available that can do the job for you. One good such script is

The most useful tool I found for network throttling was wondershaper. It worked like a charm for me. Installing it was as simple as "sudo apt-get install wondershaper" on Ubuntu. Usage is very straightforward:

wondershaper eth0 500 500 # Limits the network traffic on eth0 interface to 500 kbps
wondershaper clear eth0 # Clears throttling

For Windows there are commercial tools available such as NetFilter.

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/missing-user-75.png http://posterous.com/users/Q9gllRLHXz Sharjeel Ahmed Qureshi Sharjeel Sharjeel Ahmed Qureshi
Sun, 03 Oct 2010 10:26:00 -0700 Phonebook Poisoning Attack http://www.sharjeel.2scomplement.com/phonebook-poisoning-attack-using-social-engin http://www.sharjeel.2scomplement.com/phonebook-poisoning-attack-using-social-engin

I found that using simple social engineering it is trivially possible to make someone alter an entry in their mobile phonebook. This can be used by an attacker to redirect a victim's SMS messages and voice communication intended for a specific person, to attacker's own phone. The attack works by sending the victim an SMS from a new number, claiming to be another specific person B who is already in the victim's phonebook. The SMS claims that it is the new phone number of Person B and this message is being sent to all friends to update their phonebook. People are too occupied to verify such updates.

Imagine that you get an SMS from a new number and it says "Hello friends. This is my new number. Please update your phonebook and use this number from now onwards - Person B". In most of the cases, you wouldn't bother to verify it is indeed Person B sending this message and you'll quietly update your phonebook. Onwards, any message coming from attacker's number will appear from Person B's name. Having some prior knowledge about you and the Person B, the attacker can ask directed questions and get confidential information. For instance if you share a password with Person B and the attacker asks, you'll probably text it away.

A more interesting variation of this attack leads to true Man-In-Middle: The attacker manages to update phonebooks of two persons having acquitance with each other. Both of them's phonebook entries now start pointing to one number. The attacker forwards their SMS to each other after storing them on his own phone. In some cases voice call can also be covered with clever call forwarding. 

This attack works best in the countries where telecom proliferation is high. In such countries it is easy to buy a throw-away off-the-shelf SIM so having a new number on a spare phone is extremely convenient. Also, in such regions most of the communication is done over SMS instead of calls which is favourable for this case because in case of voice the person is easily recognized.

I tried it on few friends and it worked really well. I took the role of person B as well as the attacker and sent them the mobile number update request from a new number. Later I asked them some confidential questions related to them and me. It turned out that all of them had updated their phonebooks as well as responded to my queries without actually verifying it was me!

On a sidenote, a friend of mine wanted me to update his number in my mobile's phonebook and I tried to verify his identity. Here's how conversation went:

+92321xxxxxx: Hi, this is my number. Please update it - Ali A.
Me: Anyone can claim that he is Ali A. Please authenticate yourself!
+92321xxxxxx: Ask a question which only Ali A. can answer.
Me: What is his GMail password?
* no response *

Later I called up the claimed number to make sure that it was indeed Ali :-)

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/missing-user-75.png http://posterous.com/users/Q9gllRLHXz Sharjeel Ahmed Qureshi Sharjeel Sharjeel Ahmed Qureshi
Sat, 02 Oct 2010 00:49:00 -0700 Clippy for removing iPhone SIM http://www.sharjeel.2scomplement.com/clippy-for-removing-iphone-sim http://www.sharjeel.2scomplement.com/clippy-for-removing-iphone-sim

Image

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/missing-user-75.png http://posterous.com/users/Q9gllRLHXz Sharjeel Ahmed Qureshi Sharjeel Sharjeel Ahmed Qureshi
Wed, 25 Aug 2010 19:47:00 -0700 MySQL offline and online tables repairing http://www.sharjeel.2scomplement.com/mysql-offline-and-online-tables-repairing http://www.sharjeel.2scomplement.com/mysql-offline-and-online-tables-repairing I had a DB crash today. MySQL's tables crashed and I needed to repair them.

MySQL provides three ways of repairing its MyISAM tables:

1. "Repair Table" SQL query. (e.g. "Repair Table TableName;" from MySQL Shell)
2. Using the mysqlcheck utility. (e.g. "mysqlcheck -uuser -p DBName TableName" from command line shell)
3. Using myisamchk utlity (e.g. "cd /path/to/mysql/files/DBName; myisamchk TableName" from command line shell)

The first two methods are online methods, that is you can perform them while MySQL server is running and apart from your corrupt tables other services keep running smoothly. However these processes can be painfully slow since the server must serve data and keep its integrity while performing the repairs.

However mysqlchk is an offline method; it requires that the server must be down. It opens the server files itself and examines them on its own. This method is quite faster. For me, the online method took more than an hour while the offline method completed its job in less than two minutes. It was worth shutting down the MySQL server.

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/missing-user-75.png http://posterous.com/users/Q9gllRLHXz Sharjeel Ahmed Qureshi Sharjeel Sharjeel Ahmed Qureshi
Wed, 25 Aug 2010 04:48:28 -0700 Domain redirection with nginx http://www.sharjeel.2scomplement.com/domain-redirection-with-nginx http://www.sharjeel.2scomplement.com/domain-redirection-with-nginx Redirecting domains with nginx is pretty simple:

server {
  listen 80;
  server_name example.com;
  rewrite ^/(.*) http://parkedsite.example.com/$1 permanent;
}

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/missing-user-75.png http://posterous.com/users/Q9gllRLHXz Sharjeel Ahmed Qureshi Sharjeel Sharjeel Ahmed Qureshi
Sat, 14 Aug 2010 20:11:48 -0700 Dell Studio 15 1558 Random Shutdown and Bad Firmware Problem http://www.sharjeel.2scomplement.com/dell-studio-15-1558-random-shutdown-and-bad-f http://www.sharjeel.2scomplement.com/dell-studio-15-1558-random-shutdown-and-bad-f Earlier this year I bought Dell Studio 15 1558 Notebook. My first experience with Dell turned out to be very disappointing. From the day one I my notebook would shutdown randomly at odd intervals. It was so annoying and I had no clue to why it was happening. Several months later I got to know that Studio 15 series has BIOS issues and Dell has released several updates. I struggled with a BIOS update which was hard to get running but when it did, it crashed in the middle and turning my expensive notebook into a brick: the power light would turn on but nothing would show up as the BIOS was corrupted. Worst, the tech-support which Dell takes a lot of pride in, refused to help me saying that they don't deliver in the country I am currently in.

This was certainly not the level of satisfaction with Dell my friend have had. However I was able to get my machine back alive by utilization a special methods which I got to know from the Dell community; thanks to them!

Most of the Dell machines have Phoenix BIOS. In Phoenix a small part of BIOS ;is reserved for crisis recovery and it never gets overwritten. It acts as the BIOS of BIOS. So it is possible to have that special BIOS read from USB which contains the BIOS image and re-program it. This actually worked for me!

Here is the link that helped me: http://en.community.dell.com/support-forums/laptop/f/3518/p/19334957/19706315.aspx

I followed the following steps:

On a separate working machine:

1. Download the flash recovery tools from here: http://www.mediafire.com/?m2jdiby1xjm. Extract them in a separate accessible folder on your drive.
2. Download the latest BIOS (In my case A08). Run it, and extract it in a folder.
3. From the extracted folder, run 1558_A06.exe. It'll create WinPhlash folder in your Temp directory. (To find the location of your temp directory, go to command prompt and issue command "set temp" to find out)
4. From WinPhlash directory rename BIOS1.WPH to BIOS.WPH and move it to the flash recovery tools folder, overwriting the existing BIOS.WPH.
5. Plugin a USB Memory Stick and run WinCris.exe as Administrator. (Not running as administrator will give you error "Warning, no removable storage plugged in"). This will create three files on the memory stick.

Now on the bricked machine:

1. Remove the battery of the notebook and unplug its power.
2. Hold the power button for a few seconds, it'll remove any static.
3. Plug in the USB Memory Stick, plugin power and turn the machine on. The Led on memory stick will blink for 30 to 40 seconds after which it'll stop blinking. Now wait for a few minutes. Your computer will get restarted upon which remove USB. System will now be alive again with updated BIOS! :-)

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/missing-user-75.png http://posterous.com/users/Q9gllRLHXz Sharjeel Ahmed Qureshi Sharjeel Sharjeel Ahmed Qureshi
Mon, 26 Jul 2010 14:07:00 -0700 Daemonzing linux processes http://www.sharjeel.2scomplement.com/daemonzing-linux-processes http://www.sharjeel.2scomplement.com/daemonzing-linux-processes

If you use Linux on servers and connect remotely via SSH, many times you'd want run a process which will keep doing its work quietly in the background while you work on something else. Sometimes you'd like to process your job in the background in such a way that even if you close your session or logout, it keeps doing it work until it finishes; for instance a resizing script to create thumbnails of all images on your machine. In some cases you'd also want to control your running process such that it keeps running in background but you may stop or restart it conveniently at any time.

This blog post covers these scenarios and looks at different methods of running processes in background.

On the Linux shell, you can launch any task in background by appending "&" while launching it. The task keeps running in the background while you get back control and issue further shell related commands. However the background running process's standard output will still be shown on your shell. More importantly, if you logout while the task is running in the background, the process will exit as well. In many cases this is not desirable.

To truly run a process in the background, you need a "daemon". In computer science, a daemon is a program which runs in the background and doesn't have direct interaction with the user, neither the user has direct control over it. This means some other programs are required to control its working. Normally daemons are system processes which provide some service. For instance sshd is a daemon which provides ssh access to the users. daemons work by detaching them from standard output stream and working in background.

It is possible to daemonize a normal process. There is a command called "nohup" which tells the system not to forward the HangUp signal in case of disconnection. It also automatically redirects standard stream output to a file. Combined with "&", you can run a program in background which does not exit upon disconnection. For instance:

$ nohup ./analyzelogmessages.py *.log &

However once you launch this process, you cannot stop it except by help of other programs. For instance you can figure out the process ID with ps command and use the kill command. Also, in some cases you'd want your daemon to automatically start in case your server restarts.

To have a convenient control over your daemon, there are some tools and services available in Linux. A program called startstopdaemon is used to start and stop daemon programs. It provides various options such as running daemon as another user, jail root into different directory, change the priority, stopping already running daemon, force kill daemon etc.

$ startstopdaemon --background --start --quiet --exec sms_server -- /etc/sms_server.conf # Starts the SMS Server $ startstopdaemon --stop --quiet --exec sms_server -- /etc/sms_server.conf # Stops the SMS Server

This works well except that the system doesn't know you have a daemon and it won't start it automatically. One can put it in a init.d script. An init.d script, depending upon the linux distribution, usually resides in /etc/init.d/ and is used in much like the same manner as that of services on Windows. Creating script is simple; just create a script file and set its execute bit. On Ubuntu there is a skeleton file which acts as a template for reference.

Here is an example init.d script I wrote:

#! /bin/sh ### BEGIN INIT INFO # Provides: streamerd # Required-Start: $all # Required-Stop: $all # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Streaming Service # Description: This is a streaming server # Author: Sharjeel Ahmed Qureshi PATH=/usr/sbin:/usr/bin:/sbin:/bin:/home/sharjeel/streamingserver DESC="Streaming Server" NAME=streamerd DAEMON=/home/sharjeel/streamingserver/$NAME DAEMON_OPTS="-d /tmp/ -p 8080 -f flv " PIDFILE=/var/run/$NAME.pid SCRIPTNAME=/etc/init.d/streamerd NOHUP=/usr/bin/nohup USER=sharjeel GROUP=sharjeel case "$1" in start) echo -n "Starting $DESC: " start-stop-daemon --start -c $USER -g $GROUP \ --background --exec $DAEMON -- $DAEMON_OPTS echo "$NAME." ;; stop) echo -n "Stopping $DESC: " start-stop-daemon --stop -c $USER -g $GROUP \ --exec $DAEMON -- $DAEMON_OPTS echo "$NAME." ;; restart|force-reload) echo -n "Restarting $DESC: " start-stop-daemon --stop --quiet --pidfile \ /var/run/$NAME.pid -c $USER -g $GROUP --exec $DAEMON -- $DAEMON_OPTS sleep 1 start-stop-daemon --start --quiet --pidfile \ /var/run/$NAME.pid -c $USER -g $GROUP --exec $DAEMON -- $DAEMON_OPTS echo "$NAME." ;; reload) echo -n "Reloading $DESC configuration: " start-stop-daemon --stop --signal HUP --quiet --pidfile /var/run/$NAME.pid \ --chuid iwitness --exec $DAEMON echo "$NAME." ;; *) N=/etc/init.d/$NAME echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2 exit 1 ;; esac

Put your init.d file in your /etc/init.d and make it executable:

# chmod +x

You have to register your script with the system so that it starts it automatically when system boots. Use the update-rc.d script which registers your script with init of the system:

 # update-rc.d defaults

 

The "defaults" parameter installs it with default runlevels of your system.

For more information, see:

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/missing-user-75.png http://posterous.com/users/Q9gllRLHXz Sharjeel Ahmed Qureshi Sharjeel Sharjeel Ahmed Qureshi
Tue, 27 Apr 2010 14:17:00 -0700 How nerds offer Salah http://www.sharjeel.2scomplement.com/how-nerds-offer-salah http://www.sharjeel.2scomplement.com/how-nerds-offer-salah

Ok, time-out from code! Time to forget everything and indulge into prayers!
...
Praise be to Allah, the Cherisher and Sustainer of the Worlds Most Gracious, Most Merciful

So after the prayers I have to complete all the TODOs ... there are still flows missing in the code ... Great Idea! Atleast for the frame-by-frame processing I can spawn another efficient process ... Oh God ... I am praying ... c'mon ... concentrate!
Master of the, Day of Judgment. Thee do we worship, and Thine aid we seek.
Wait ... did I put security checks while deserializing objects from untrusted source? Gotta check 'em as well
Show us the straight way.
Yeah, the underlying library takes care of sanitizing the input. Thats fine!
The way of those on whom Thou hast bestowed Thy Grace, Those whose (portion) is not wrath and who go not astray.

So we are left with only two flows. That should be simple in C++
.
.
.
May peace be upon you (Prayer Concluded)

Hey! What was the last important point came to my mind during second rak'at???

And here is how the idea of this blog post was generated:

ufff .... why can't I concentrate?
Say: He is Allah the One and Only; Allah, the Eternal, Absolute;
These thoughts are so annoying maybe I should write a blog post about them
He begetteth, not nor is He begotten;
And post them to Facebook as well! And there is none like unto Him.
wait ... was it the first rak'at or the second one? :S

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/missing-user-75.png http://posterous.com/users/Q9gllRLHXz Sharjeel Ahmed Qureshi Sharjeel Sharjeel Ahmed Qureshi
Sat, 30 Jan 2010 12:08:00 -0800 My Nikah http://www.sharjeel.2scomplement.com/my-nikah-sermon http://www.sharjeel.2scomplement.com/my-nikah-sermon

sharjeel-nikah-sermon.mp3 Listen on Posterous

My Nikah was held on 24th January 2010 at DHA Mosque Lahore after Asr at 4:30 PM. The sermon was delivered by Dr. Moulana Sarfraz Awan on 24th January 2010. Audio Recording is attached.

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/missing-user-75.png http://posterous.com/users/Q9gllRLHXz Sharjeel Ahmed Qureshi Sharjeel Sharjeel Ahmed Qureshi -
Sun, 25 Oct 2009 18:03:34 -0700 Startupping Hajj http://www.sharjeel.2scomplement.com/startupping-hajj http://www.sharjeel.2scomplement.com/startupping-hajj For a Startup Founder getting psyched up for Hajj is simple: There are gonna be extremely hard times, you'll have to do a lot of things yourself, you should stay patient, be calm, don't complain, be very resourceful during the hard times and expect a lifetime reward if you do it well. Wait, you've been through this before, haven't you? :)

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/missing-user-75.png http://posterous.com/users/Q9gllRLHXz Sharjeel Ahmed Qureshi Sharjeel Sharjeel Ahmed Qureshi
Sun, 25 Oct 2009 17:22:00 -0700 Migrating from XP to Windows 7 http://www.sharjeel.2scomplement.com/migrating-from-xp-to-windows-7 http://www.sharjeel.2scomplement.com/migrating-from-xp-to-windows-7

I've been using MS Windows since version 3.1 and ever since Vista is the only OS by Microsoft which I haven't even tried; and I'm glad I didn't. No comments required on this. However I must say the next effort by Microsoft, i.e. Windows 7 is commendable. I tried to switch over to Mac but the non-standard shortcut keys of Mac for a keyboard ninja like me, and a few minutes of usage with Release Candidate new OS successfully proselytized me to Windows 7.

However Windows 7 doesn't have built in support for upgrading from XP. One could follow the painful procedures of upgrading XP to Vista first and then to 7 and struggle with driver issues. Here is a much convenient way.

For me, the most important thing was to retain my profile settings and then my programs as well.

Windows 7 comes with a utility called Migration Wizard. It lets you backup your settings and restore on a fresh install.

To use it, just boot your Windows XP and insert your Windows 7 installation disc. From the folder \support\migwiz\ run migwiz.exe. It'll let you choose the stuff you want to backup. Keep the file at a safe place (e.g. a USB disc). Now install Windows 7 and run the same tool. This time choose the restoration option and point it to the file in which you saved settings. It'll take some time but it is worth it.

Here is a detailed tutorial: http://www.howtogeek.com/howto/3179/migrate-xp-to-windows-7-with-easy-transfe...

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/missing-user-75.png http://posterous.com/users/Q9gllRLHXz Sharjeel Ahmed Qureshi Sharjeel Sharjeel Ahmed Qureshi
Tue, 08 Sep 2009 18:34:00 -0700 Future Secondary School English Examination 2.0 http://www.sharjeel.2scomplement.com/future-secondary-school-english-examination-2 http://www.sharjeel.2scomplement.com/future-secondary-school-english-examination-2

Looking at the way technology is influencing our everyday speaking and writing styles, I think it won't be long before even the most traditional of our schools would get influenced. I remember back in 1997 when I was doing my matriculation studies at Crescent Model School, the teachers did adopt to write letters the way email is indented (i.e. double new line between paragraphs and no indentation at the starting line)

Based on these thoughts, I think the future exams of English might look something like this:

Board of Intermediate & Secondary Education Pakistan Matriculation Exam - English B Date: 10th March 2015

Total Marks: 100 Time Duration: 1 hour 45 Minutes

Q1. Write a blog post entry on one of the following having no more than 2000 characters (20 Marks)

  • Life in a Big City
  • Ev0lut10n of cont3mp0r4ry scr1pt$

Q2. Suggest titles for flickr photos tagged with following keywords

  1. thirsty, crow, pitcher, pebbles (5 marks) 
  2. lol, cheeseburger, computer, router (5 marks)

Q3. Write an SMS to your Uncle thanking him for the gift he sent. You may concatenate two SMS to avail 300 characters limit. (10 marks)

Q4. Write an e-mail application to your headmaster requesting him to allow the use of social networks on the school network (15 marks)

Q5. Write a snail mail letter, having no more than 100 words, to your grandfather inviting him to use GMail (15 marks)

Q6. a) Translate into English: "Hy Dad. Rcvd da cash. Cudnt buy books cuz Friendz wanna party. LoL! GTG. Thx. TC" (10 marks)
b) Translate the following Roman Urdu into English "Zindigi k nashebo faraz mein insan par aisa waqt ata hai jab uss ko har taraf andher nazar ata ha" (10 Marks)

Q7 a) Tweet your friend inviting him to spend coming summer vacations with you (5 Marks)
b) Update your Facebook status telling everyone that you won't be available for the next few days but would still keep in touch via net (5 marks)

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/missing-user-75.png http://posterous.com/users/Q9gllRLHXz Sharjeel Ahmed Qureshi Sharjeel Sharjeel Ahmed Qureshi
Thu, 20 Aug 2009 09:39:00 -0700 Filter crappy posted videos from Facebook feed http://www.sharjeel.2scomplement.com/filter-crappy-posted-videos-from-facebook-fee http://www.sharjeel.2scomplement.com/filter-crappy-posted-videos-from-facebook-fee

Once Facebook's feed used to be very useful informing you about the updates of friends by their status, . I feel my Facebook feed has been hijacked by redundant and time wasting posted videos. So I wrote a small GreaseMonkey script to filter out posted videos. Here it is:

// ==UserScript== // @name           Facebook Remove Vids // @namespace // @description    Removes videos from your Facebook Feed // @include        http://www.facebook.com/*home.php* // @include        http://www.new.facebook.com/*home.php* // ==/UserScript==   function cleanUpPage() {     var stories = document.getElementsByClassName("UIIntentionalStory");       for ( var i = 0; i < stories.length; i++ ) {         var sHTML = stories[i].innerHTML;         if ( sHTML.match("class=\"UIMediaItem_video") || sHTML.match("class=\"swfvideo") ) {             stories[i].style.display = "none";         }     } }   window.addEventListener("load",     function() {         t = setInterval(cleanUpPage, 1000);     }     , false);

I must say that after removing those videos, very little has been left in my feed :)

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/missing-user-75.png http://posterous.com/users/Q9gllRLHXz Sharjeel Ahmed Qureshi Sharjeel Sharjeel Ahmed Qureshi
Wed, 22 Jul 2009 07:27:00 -0700 Attempt Retries decorator in Python http://www.sharjeel.2scomplement.com/attempt-retries-decorator-in-python http://www.sharjeel.2scomplement.com/attempt-retries-decorator-in-python

In certain situations particularly when dealing with networks and distributed systems you'd want your program to retry certain a particular operation certain number of times in case it fails before giving up. For instance your program is trying to connect to a mail server which is due to network connectivity temporarily giving socket error.

The simple way is to put a loop, try certain number of times and if the result still fails give up. I found this pattern normal so I wrote a decorator in Python which can be generically used.

def attempt_retries(func, retries=3, delay=3, IgnoreException=Exception):     """     Decorator for ignoring certain exception for certain number times and retrying with certain delay     e.g.   func = @retry(connect_imap, 10, 5, SocketError) # Tries ten times     e.g.2. retry(connect_imap)(username, password)     """     def dec(*args, **kwargs):         for i in range(retries-1):             try:                 return func(*args, **kwargs)             except IgnoreException:                 sleep(delay)         func(*args, **kwargs)     return dec

Usage:

attempt_retries( server_connect, 10, 20, SocketError ) ( host, user, pass)

or

r_server_connect = attempt_retries( server_connect, 10, 50, SocketError ) r_server_connect( host, user, pass)

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/missing-user-75.png http://posterous.com/users/Q9gllRLHXz Sharjeel Ahmed Qureshi Sharjeel Sharjeel Ahmed Qureshi