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.

Dell Studio 15 1558 Random Shutdown and Bad Firmware Problem

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! :-)

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/movino
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:

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

My Nikah

  
(download)

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.

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? :)

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...

Future Secondary School English Examination 2.0

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)

Filter crappy posted videos from Facebook feed

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 :)