Inspirated

 
 

June 4, 2010

How NOT to copy MBR with the dd command

Filed under: Blog — krkhan @ 8:39 pm

Yesterday I needed to copy the MBR of a drive over another. Googling a little I found the following command in various tutorials:

-bash-$ dd if=/dev/sda of=/dev/sdb bs=512 count=1

Where /dev/sda and /dev/sda were the original and target hard disks respectively. The command did complete its work in a snap but it also made me learn a thing about MBR structures the hard way: Only 446 bytes of the MBR contain boot code, the next 64 contain the partition table!

The implications of the lesson being, if partition tables of both hard disks differ — which unfortunately was the case with me — the partition table of the target hard-disk will be overwritten. The correct way would therefore be:

-bash-$ dd if=/dev/sda of=/dev/sdb bs=446 count=1

In case you did mess up the table, I recommend TestDisk for recovering your partitions.

Tags: , , , , , ,

May 20, 2010

Facebook in Pakistan — in a nut-shell

Filed under: Blog — krkhan @ 3:32 am

It’s on everybody’s tongues in my country and I’ve been inquired about my geek opinion throughout the day. Notwithstanding eon-long rants about it, I’ll just quote this piece of gold from the geek authority itself, xkcd:

xkcd: Duty Calls

Tags: , ,

April 27, 2010

Finally there — Google Summer of Code 2010

Filed under: Blog — krkhan @ 1:02 am

GSoC 2010 Logo

Fate has a curious sense of humor. After having 8 of my proposals rejected in past 3 years for Google Summer of Code, I had 2 of them selected in the same year. In GSoC terminology, I became a “duplicate” student. Now, the standard practice for such cases is that the administrators of both organizations interested in the student get together in a “deduplication” meeting and resolve the conflict. However, Maria Randazzo (the program administrator from the Ubuntu organization) was kind enough to ask my preference regarding the project I’d like to work upon.

This put me in a rather uneasy position as mentors from both organizations (Bryce Harrington from Ubuntu & Alexey Khoroshilov from The Linux Foundation) had been really helpful during the application process. In the end however, I chose Ubuntu since its proposal focused on Arsenal and Python which I found relatively more familiar than Alien and Perl. I had also already collaborated with Bryce for some Arsenal patches before so it was easier for me to get up-to-speed with the Ubuntu proposal.

The proposal itself is in fact publicly viewable at this link. Summarizing my feelings, I’ve never looked forward to a summer as much as this one.

“If a June night could talk, it would probably boast it invented romance code.” —Bern Williams

Tags: , , , , , , , , ,

April 1, 2010

71 days of E71: Top 10 3rd party applications

Filed under: Blog — krkhan @ 2:05 pm

While I would have sold my clothes, PS2 as well as my soul to get my hands on a N900, I couldn’t strike a practical deal and in the end had to settle for E71. Now, while E71 does not ooze s** by running a full-fledged Linux distro it still does a pretty good job of running Symbian. The specs are fun, the keypad is great and the build quality is nothing but ergonomic love.

After completing 71 days of tinkering with the new phone, I have settled on the choice of apps which would become an integral part of my digital life. I’m listing the top ten here, but the arrangement is in no way meant to be indicative as an absolute index of application quality. These are just the ones that I found useful.

10. ScreenSnap — Honorary Mention

It would be a bit unfair to not list the very application that powers the visual aspects of this post. So here we are with the self-referential snap:

ScreenSnap Screenshot

9. SmsOne — Hassle-Free Flash SMS

“Flash” texts — the ones which always instantly show up on the recipient’s cell and are not saved in the inbox unless specifically made to — have always been a speciality of applications with poor interfaces as well as poorer integration with the rest of the phone. SmsOne, on the other hand, has a simple interface with excellent phonebook integration for making the job as simple as possible.

SmsOne Screenshot

8. Mobipocket MobiReader — eBooks Made Fun

Reading a large PDF file on your E71 is indeed possible, but it takes away any fun whatsoever by forcing you to deal with redundant scrolling and weird font sizes. MobiReader combined with the desktop software Calibre is the ultimate eBook reading experience on Symbian phones.

MobiReader Screenshot

7. Gravity — Pulling Tweets Consistently

The one word for summarizing Gravity would be: slick. Of all the Twitter applications for Symbian — and there are quite a lot — Gravity is the most organized, reliable and pretty-looking competitor around.

Gravity Screenshot

6. PuTTY — That Insane Power in Your Hands

I’m lying down in my bedroom and I want to play this song on the speakers in my drawing room. I’m in my university and I want to start this download on my laptop which is unfortunately back at home. I’m in another city and I want to see the contents of this file which is in my home PC.

I can. Because I have that command-line access at my fingertips:

SmsOne Screenshot

5. mIRGGI — IRC Never Dies

Open-source — being the distributive collaboration that it is — depends heavily on mailing lists and IRC channels for communication. For the latter, mIRGGI works flawlessly. In fact, you can even do fancy stuff like using different network connections for different channels.

mIRGGI Screenshot

4. Python — “It’s …”

For all the comparisons made over the years between Perl and line-noise, Symbian C++ easily beats both by a mile. Which is why your choices are rather limited if you want to program for Nokia phones while preserving your sanity at the same time. Your best bet is to go for Maemo. Unfortunately, that ain’t exactly an affordable option for everyone. The other way is to use PyS60 rely on that programming language which makes every other alternative pine for the fjords.

PyS60 Screenshot

3. MSDict Viewer — Dictionaries which Help

A dictionary is one of the least useful things you can carry around. Even with one of them installed on your phone, they rarely get used. Similarly, the pronunciation guides used in those dictionaries are cryptic symbols at best. Add the ability of audio pronunciations and you suddenly have a lovely app referring which almost becomes an addiction.

MSDict Viewer Screenshot

2. Google Maps — Never Lose Yourself

For people who’re not especially good with directions, there couldn’t have ever been a better solution:

Google Maps Screenshot

1. Opera Mobile — Synonym for Excellence

Even if this list is tailored more to my requirement, get some hundred people to make similar ones and Opera will be the topper in majority of the rankings. Opera bridges that gap between mobile browsing and real browsing and is one of those applications which epitomize how software should be engineered.

Opera Mobile Screenshot

Tags: , , , , , , , , , , , , , , , ,

March 3, 2010

The Defense

Filed under: Blog — krkhan @ 10:08 pm

Continuing the process of presenting my proposal for the graduation project, I was required to do a presentation. Now, I have never really liked PowerPoint and for more reasons than it being a product of Microsoft (I was never really into OpenOffice.org Impress either).

In fact, I have never liked doing presentations in the first place. My preferred means of communicating an idea is through written material or face-to-face discussions. Anyhow, seeing as I had to do a formal presentation, I turned towards the solution that would provide some additional attraction for me: LaTeX Beamer.

After fiddling around with my .tex for a few hours, I was able to create something which looked [*] far more professional, sexier and informative than anything I had ever created using traditional presentation software:

ittc-defense-presentation.pdf
Presentation Screenshot

To view the presentation you have to open it in “Slide Show” mode of your favorite PDF reader. What totally blew me away was the ease with which I could create lovely bibliographic references, mathematical equations and little fun things like navigational bar on top of every page. Perhaps it’s got to do something with the mindset of a programmer, but I certainly became more productive with Beamer within a couple of hours than I had been throughout my experience with PowerPoint/Impress.

[*] Whether they were professional, sexy or informative is a totally different matter and has very little to do with either LaTeX or Beamer.

Tags: , , ,

March 2, 2010

GoDaddy/WordPress ninoplas Base64 virus and the fix

Filed under: Blog — krkhan @ 7:40 pm

Update: The virus seems to have affected only GoDaddy websites, hence the change in title.

Few hours ago I opened my website and noticed some rather strange Javascript hanging around the bottom. After some inspection, it became evident that every page on my blog was trying to load an IFrame to some place called ninoplas.com. Turns out, I wasn’t alone and there are other users as well who are affected by this. Judging by the fact that different blogs were attacked at the same time, this was in all probability the result of a security hole in some plugin or the core itself.

The virus acted by adding a piece of encrypted code on the first line of all PHP files on the server. It’s rather unsettling to consider the extend of damage that could have been caused with the write access to those files. Still, the damage could be rectified by simply deleting those lines. I wrote a tiny script for doing this job which cleans the ninoplas virus from all the PHP files in the current directory:

clean-ninoplas.sh

Warning: While this script has worked for me, I am in no way providing any guarantee for how it behaves on other blogs. Backup your blog as well as database before executing this script.
You have been warned.

Using the fix is a simple matter of:

-bash-$ cd wordpress
-bash-$ wget https://inspirated.com/uploads/clean-ninoplas.sh
-bash-$ sh clean-ninoplas.sh

And don’t forget to backup everything again after cleaning up. The security hole — if there is one — has still not been tracked and if it’s in the core or some plugin which you’re still using, the virus might not be so benevolent next time.

Tags: , , , , , , ,

February 16, 2010

“Houston, Tranquility Base here. The Proposal has landed.”

Filed under: Blog — krkhan @ 10:51 pm

Baffling all reason known to mankind, I have somehow entered my final year of engineering — that is, after earning every conceivable grade on my transcript. As is the custom, I was supposed to work on a graduation project and the first step included presenting a proposal and defending it. Brainstorming sessions for a project idea left me with classical stuff such as HAL-9000 or the Nebuchadnezzar hovercraft. At which point I decided that I simply wasn’t creative enough to come up with an idea on my own and asked around for help. After a few days of frantic Googling and inept socializing with senior academia members, I finally found something which at least managed to sound horrible: an Intrusion Tolerant Threshold Cryptographic System.

The proposal can be found at this link. If the contents seem a bit sparse to you, reread the title as “A Not-At-All Fault Tolerant Attempt at Getting to Grips with LaTeX and BibTeX. Although, I’m not entirely sure my attempts at doing something with latex were more successful than Geroge’s.

“And you wanted to be my latex salesman.” — Jerry Seinfeld

Tags: ,

November 15, 2009

code.inspirated.com

Filed under: Blog — krkhan @ 8:48 pm

While blogging over the years, a good deal of posts containing useful code came up and then disappeared under that “Next Page” link. While I have no issues with regular posts moving down the stack, I did strongly feel that the ones containing code should be cataloged separately in some place. Similarly, when new version of a program from earlier posts was released, it also created a mess in the previous post chain for that program as I had to update all of them to the latest link.

The solution was pretty simple. Instead of using the main blog’s pages, I created a mini-site at code.inspirated.com where I intend to manage the bits and pieces of programming spread on Inspirated. So far, I like the results of using the rather nifty software CMS Made Simple. As a matter of fact, if you have ever tried deciding between available CMS solutions and have succeeded in less than an hour, I salute you. The number of CMS projects out there far exceeds the number of Linux distributions that have ever been created. And that says a lot.

Tags: , ,

August 1, 2009

Writing a minimal shell in Python

Filed under: Blog — krkhan @ 1:48 am

Being a Unix geek has its own little benefits. For example, when a friend wants you to code a shell for his Operating Systems assignment, you can extort a lunch out of him for the services. Moreover, if you can somehow get him to convince his teacher for accepting submissions in Python, you can have s** with the code itself.

The bare-essentials shell was required to have the following:

  • Support for internal commands such as cd or ls which would be implemented using system calls.
  • Support for launching external programs with arguments provided to the shell — optionally putting them to background with an ampersand at the end of the arguments.

That is it. No fancy intput/output stream redirection, no jobs, no pipes. Just a simple launcher. A quick doze of reflective programming resulted in a class that checked the given commands against member functions (e.g., Shell.on_cd is queried for “cd path“) and called them to process the input. In case of unrecognized commands, the default handler is called which in turn uses the subprocess module and attempts to launch the command as an external program. Support for escaped or quoted arguments wasn’t required (the assignment recommended tokenizing strings at spaces), but the godsent module … :

import shlex
# ...
args = shlex.split(command)

… allowed me to support proper argument parsing with only half a line of code anyway. Similarly, connecting to the standard input/output of the child program wasn’t in the requirements, but the simple call … :

import subprocess
# ...
proc = subprocess.Popen(args,
	executable = args[0],
	stdin = sys.stdin,
	stdout = sys.stdout,
	stderr = sys.stderr)

… did the trick perfectly; allowing proper executions of commands such as “cat -“.

The complete code is downloadable here. Unfortunately, coding was the easy part. Getting the guy to pay for the extorted lunch wasn’t and as of this writing, I’m still deadlocked on that front.

Tags: , , , , , ,

July 30, 2009

Blog structure change

Filed under: Blog — krkhan @ 5:45 am

While starting this blog back in 2007, I didn’t care much about the URL being redundantly long in form of https://www.inspirated.com/wordpress/. Truth be told — being the lazy bum that I am — I didn’t want to go through the administrative troubles of updating the site structure to have something brief. That is, until today. As I was registering this blog as my OpenID at Slashdot I really got fed up with the sub-directory being part of my claimed identity. The result of this major aggravation was a regular Apache nutjob. First of all, I followed the instructions on this page. Then, I put together a quick .htaccess rewrite to ensure that old addresses (e.g. /wordpress/anything) still get permanently redirected to new ones (i.e. /anything):

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*wordpress\/(.*)$ \/$1 [R=301,L]
</IfModule>

And just as everything seemed to work perfectly, the fgallery plugin insisted on ignoring the new URL. Digging up a bit, the culprit turned out to be a bug in fgallery‘s implementation which constructed gallery links with the WordPress address instead of the Blog address (the difference is critical in installations such as mine where WP’s core files resides in a subdirectory but the blog uses root directory for friendly URLs). The fix was trivial (had to replace a few get_bloginfo('wpurl') calls with get_bloginfo('url') instead), and lo and behold! Everything’s functional again. I should have done this little exercise a long while ago but well, better late than never. As a sidenote, this does not mean that I am reconsidering my slothful position on other pending tasks for the blog. Since for most of them I adhere to Georgy Shaw’s version of the quote instead, i.e., better never than late.

Tags: , ,
« Previous PageNext Page »