Thursday, December 3, 2009

setting a command shortcut in linux

The alias command helps to create your own custom shortcut name to a linux command. The format is -
alias name='command'
An example alias view all hidden files -
alias lh='ls -la'
An example alias to cd to the webserver root -
alias webroot='cd /usr/local/apache2/htdocs'
An example alias to run php in CLI mode -
alias php='/usr/local/apache2/php/bin/php'
To list all the available aliases, just type alias on the command line.

If you would want the aliases to be available everytime/forever, add them to your .bash_profile

Wednesday, December 2, 2009

mysql :: tab to autocomplete table names

If you use mysql client, and the table names are quite lengthy to type, you can enable mysql's auto-rehash option to use the auto-complete feature. This is similar to how one would use tab key for auto-completion in command prompt.

When invoking mysql client, issue auto-rehash option as below -
mysql -u uname -p --auto-rehash
However, do note that the mysql client will startup slowly as it requires to create the hash on the table names etc.

Tuesday, June 16, 2009

Orkut no longer features in GMail's Top Bar?



Just noticed! Orkut no longer features inside GMail's top bar. Is it for all? Or is it just me?



17-June Update: It's been there now since morning. So must been only temporary.

Monday, June 8, 2009

Wishful Maths

It's been over a month that Stephen Wolfram's WolframAlpha has gone live; and I've been following the developments closely. It's greatness and awe-factor notwithstanding, I doubt I would have used it for anything else other than solving Maths. I did horribly bad in my CET Maths exams, and imagine how uber cool it would have been to have a tool that would solve something complex like integrate x^2 sin^3 x dx for me. :-P


For everything else, I believe dear ol' goog is better.

I mean, I tried to find the distance from Bangalore to Delhi, and it drew up a neat page with map and super-cool calculated values.



Only that, the values were far from reality. The results showed that it would take approximately 118 minutes by flight. A brief check on travel sites state that most flights take around 2 hours 40 mins from Bangalore to Delhi. That's not so bad, considering we probably don't have planes that fly at 550 mph. The driving time is given as 19.7 hours, which leads us to the fact that not all things in life can be equated using Maths. :-)

And as to the eternal question, I was mildly surprised that W|A did actually have a satisfactory answer.

Monday, May 4, 2009

social search: get questions answered by your friends through Aardvark

People think I am skewed towards Google a lot. Actually, am not! Google, is almost always, the second choice when I need information. The first I turn to, are most always people. If I am stuck with UI, I usually turn to Renjith; if it's python, then there is Vikalp; if it's machine learning, there's Srinivas to lend a helping hand; if it's about the latest in web technologies, or anything about good food joints in Bangalore, then there is always Arjun.

People, unlike Google, can give factual answers, and that allows me to complete my task fast and easy. I would rather go by what my friends have to say than what I find in some obscure website discovered through Google.

And then, there's always the trust factor, and of being approachable. Would you mind, if your friend (or a friend's friend) asks you a question about a topic you are knowledgeable about? Chances are, you would happily oblige!

And, it is for this reason, that I believe Aardvark is a cut above the rest.


Welcome the next generation in Social Search. It is somewhat related to web search, in the sense that you search the web to find information within them; whereas in Social Search you try and find people who are capable of giving you the information that you seek. Simply put, Social search is all about finding information from real people.

I have a few invites left. So, if any of you are interested in trying it out, then drop me a mail, and I will send you one.

Tuesday, April 28, 2009

Access your gmail securely!

I hope all of you are using gMail with the https setting enabled. If not yet, it would be worthwhile to walk through this article. :-)



Monday, April 20, 2009

Make bixeenews your new friend on gtalk

It's IPL; and I sincerely hope all you cricket fans are on gtalk (google's chat application); for now, there is a novel way to be in sync with cricket happening around the world. Vikalp, a friend, has built a chatbot that pushes instantaneous updates to you. :-)

Once subscribed to a match, the ball-by-ball commentary is pushed across during the complete duration of the match. If you think this is too much, then no problem; for you can also choose to get only the scores pushed to you. The bot can also push stock information on request.

The advantage of extending your friendship with the bot is that, it will keep pushing information to you; much unlike a website, where the onus is upon you to keep refreshing the page.

The process of adding the bot is simple. All you have to do is add bixeenews@gmail.com as a contact in gtalk.



Once added, type help to get a list of commands you can use. Go ahead and enjoy! :o)

The bot loves feedback, and will depend on you to help it serve you better. You can send feedback through the bot itself, or mail to vikalpsahni_at_gmail_dot_com. I am sure he would be happy to respond, as much as the bot! :o)

And oh yes! Do root for Bangalore Royal Challengers! And for Rahul! :o)

Friday, April 10, 2009

images in gmail

If you ever wanted to embed an image within your Gmail email content, there's a new labs feature available now that helps you do that.

Enable the labs feature.




You will notice a new icon in your compose editor. Click on it to open the uploader.




Upload the image, and get along with the content. :-)

Tuesday, March 31, 2009

remove unread count in google-reader

I use google reader a lot. I've subscribed to friends' blogs; tech news, articles, world updates, and yes, even cartoons. I find it overwhelming sometimes when I have too many things to read-up, and too little time to do so. I have noticed on a few occasions that the count of number of items unread against each of my subscribed feeds, pumps up my blood a few notches, and I find myself deadlining to bring that count down to nil.

The concept is not entirely new though, as Gmail Labs has a setting to switch the unread count off from gmail labels.

I looked around to see if there are any readily available scripts to hide the unread count; didn't find any easily; and spent the next few minutes in hacking my own. And voila! You can find my script at http://userscripts.org/scripts/show/45551 .

And.. Oh.. Another thing, you will need the Greasemonkey addon for this to work! :-)

This is how my gReader looks before and after the application of the script. Be easy now, my heart!

Tuesday, March 24, 2009

the weatherman

I stay seated behind closed doors and barricaded windows that don't even allow light and wind to seep in without permission... Is it raining outside... How do I know... Who will tell me...


Thanks GMail!

Friday, March 13, 2009

conversations on google reader

I believe you would have gathered by now that am an ardent user of google reader, as my multiple mails being sent through it would testify. There might possibly be other products that probably do a better job; but then the gReader coupled with the google account itself, has kept me hooked onto it.

Starting yesterday, Google Reader introduced allowing for comments on feed items.


Your reader friends then can comment on your shared items, and you can have a whole conversation around it. You can even discuss about what you had for breakfast, and how bad the traffic was. Not to worry, the comments view are restricted to your reader friends only. Click on the above picture for a bigger view.

Friday, February 27, 2009

review : mozilla add-on : FireShot

Once in a while (like 5 times in a day) I find the necessity to take a screenshot of the webpage, edit it for annotation, and then send it across. My normal procedure was PrtScr + open MSPaint + paste the screengrab + edit according to requirements. Yeah! I know.. Ugly!!

And then I chanced upon FireShot; a firefox add-on. Yes again! Firefox is my browser of choice.

FireShot is one hell of an awesome application. I can instantly save (or) edit the current page. Annotate it as I wish; save it in different formats; or even copy it to the clipboard and paste it to Word or PowerPoint.

The following grab details what all functions it allows -


It even has a Pro version; albeit a paid one, and more suited for content creators. For me, the free version works just fine. I highly recommend FireShot. It greatly enhances one's productivity.

Friday, February 20, 2009

google maps recommends you to kayak

Abhishek pointed me to an interesting link. It was for driving directions on google maps from Seattle to Honalulu; right across the Pacific ocean. The amount of data they have; and the ways they find to crunch it. These guys never cease to amaze me.

Other than that, what I really liked is this (click on the image for a bigger picture) -


Apart turning left on this road and turning right on that; google recommends you to kayak 4000 odd kms across the Pacific. Given that it estimates about 14 days and 6 hours for you to reach your destination; I would like to believe the 14 days are for kayaking itself, even for a guy in supreme fitness like me.

If the image appears blurred, then you can catch the action here. Maybe you could brave yourself to walk. You can't escape the kayaking though even then. :o)

Tuesday, February 10, 2009

review : mozilla add-on : firebug

I have created a web page. Now, should I align that DIV to the left? Or should it be centered? Will it look good if the font size is 11px or 12 px? should I change the background color to yellow or magenta? Now again, what was the class selector that I used on that DIV? How much should I specify the left value as for this element, to align it with the rest?

Imagine wanting to do all that and more... You update your web page on the server. Refresh! Tweak the page on the server! Refresh! Tweak again! Refresh!

Enter Firebug. Firebug is a mozilla addon that helps ease a web developer's life. It allows you to inspect the html elements on a page; edit and modify them; run remote scripts; see the network utilisation; view the various requests that your page makes; view each request's query and response; inspect the DOM; inspect the layout of the page; and the list goes on and on.

For someone looking to architect the web, firebug is a must-have.

Friday, July 4, 2008

igoogle job search tool

Vok.. So, my first open source offering is live and begging for you to use. bixee is a product of my employer's family, and the job search tool developed gives you a convenient way to search for jobs across a multitude of job sites. Please use it and tell me how bad it is. Email your correspondence address too along with your comments, so that I can send the bogeyman to drop a ton of bricks on your head. On the other hand, kind words and kudos are also solicited, and will be greatly appreciated too.

Make my tool a permanent fixture on your google homepage; lest you want the bogeyman dropping by. It's fairly simple actually. You just have to click the link below, and you can then add the tool.

What?!!? You don't use ig ? awww... c'mon...
sign in .. It's definitely got to be one of the best things around.


Add to Google


Thursday, February 14, 2008

An art called Smart Documentation

There is no denying the fact that if there is one aspect of software engineering that gets the least importance, then it is documentation. No wonder that thoughtful people tend to advocate it all the more. We, then, in our exuberance, barf out pages and pages of text, which, even we would not have read, had it been spewed by another.

Be informed, that no software, either product or project requires end-to-end documentation. It is going to be shelved anyway. What any software needs, is a smart document. And, all a smart document will need, is a smart YOU.

I list out a few points below. Follow them at your own risk [ You wouldn't want to be called smart. Would you now? ;o) ]

  • Know your audience.
    The first thing is to know whom you are targetting with your document. Is it the techie geeks within the organization; then code and design snippets would do. Is it a bunch of freshers; then you may have to allow them to soak in the details rather than throw jargon at them. Is it the business people; then be sure to outline information that needs their buy-in. If it is a bunch of dunderheads; then don't even bother; for they don't even care.
    Know that, no one document is suited for all people. It would be advisable to serve up different documents for different segments of people; rather than have it all in one single document.

  • The scope
    The questions you have to constantly ask yourself is - Is the item I am writing necessary in the overall context?
    Know the scope of your document and stay within the limits of it.

  • blah! blah! zzz!!!!
    In technical documents, always try to avoid long paragraphs with huge lines of text. This will do no good than to put the reader to sleep. Always look to have details put in point-wise lists. It is always easier to register 5 points with 2 lines each, than a paragraph with 20 lines.

  • A picture can speak a thousand words.
    Use pictorial diagrams liberally within the document. You will be surprised at what a simple flow chart can get through to your audience than carefully worded text.

  • Hand sketches.
    So now you know you have to have diagrams in your document. So that means you have to master MS Paint & Visio??? Good, if you do. If not, then just draw up a sketch with a pencil, scan and attach. The idea, is to get the message across; not to impress.

  • Granularity.
    The level of granularity you go within a document is again based on your target audience. Do not burden the reader (and yourself) with unnecessary information. Stay short; be sweet; and to-the-point.

  • Index
    The Document Index is one of the most important parts of your document. It gives a bird's eye-view to the reader of the content; and will also enable the reader to move to the required section swiftly.

  • Indent
    Try not to have more than 2 indent levels in your document. Make sure there is minimal white space visible, and indents bring in white space.

  • Use fonts wisely.
    It is always easier on the eyes if the text is consistent throughout the document. So,
    • try not to colorize text.
    • try not to have variable font-sizing within a paragraph of text.
    • try to draw reader attention using italics and bold.
    • try to use fonts relevant to the document. Arial is always a better choice over ComicSansMS for professional documents.

To end, a point to ponder!!! More often than not, lengthy documentation (or) creating a lengthy document gives one the notion of contributing/working a lot. Beware that you do not fall into the trap of false thinking. Though documentation is a good-to-have activity in any organization, false documentation only leads to productivity degradation of the individual.

Tuesday, October 9, 2007

JavaScript function to make an AJAX call

How many times have you had to go to the web, to look how to make a proper AJAX call? Many? Well.. Not anymore. Use this JavaScript function to make an AJAX call and process the response.

/**
* Purpose: to make a client-side request to the server, and obtain the response
*
* Input Params:
* 1. pURL - string - request URL
* 2. pPostVars - string - POST variables
* 3. pCallbackFunc - function reference - function that is to be called on
* successful response
* 4. pAsync - int - if request to be asynchronous - 1/0
*
* Output Params: none
*
* Return Value:
* on success - string - the response from the server
* on failure - bool - false
*
* Notes:
* 1. By default the request will *NOT* be asynchronous.
* This behaviour can be changed by the param pAsync.
* 1 is for asynchronous, and 0 is for synchronous.
* 2. By default the request method is GET. If however pPostVars is passed to the
* func, then the request method will be POST.
* pPostVars will a set of post variables as
* "var1=val1&var2=val2&var3=val3&varn=valn"
* 3. pCallbackFunc is a reference to a JS function. If specified, this function must
* mandatorily take a parameter to which the response string will be passed.
* 4. In most cases, if the request is going to be asynchronous, then it is always
* better to pass a callback function to do needful scripting after the response
*/
function GetServerResponse ( pURL, pPostVars, pCallbackFunc, pAsync )
{
var http_request = false;
var http_method = "GET";
var request_type = false;
var server_response;

if (pPostVars && pPostVars != "") var http_method = "POST";
if (pAsync && pAsync == 1) request_type = true;

// Browser - IE
if (window.ActiveXObject)
{
try { http_request = new ActiveXObject ("Msxml2.XMLHTTP"); }
catch (e)
{
try { http_request = new ActiveXObject ("Microsoft.XMLHTTP"); }
catch (e) {}
}
}

// Browser - Mozilla, ...
else if ( window.XMLHttpRequest )
{
http_request = new XMLHttpRequest ();

// some versions of Mozilla browsers won't work properly if
// response from server doesn't have xml mime-type header
if (http_request.overrideMimeType)
{
http_request.overrideMimeType("text/xml");
}
}

// unable to create xmlhttp obj
if (!http_request)
{
alert('Error : Cannot create an XMLHTTP instance');
return false;
}

// return server output on successful retrieval
http_request.onreadystatechange = function() {
if ( http_request.readyState == 4 )
{
// successfully got response
if ( http_request.status == 200 )
{
// case : if callback function specified,
// pass on the server response string to it as a parameter
if ( pCallbackFunc && typeof(pCallbackFunc) == "function")
{
pCallbackFunc(http_request.responseText);
}

server_response = http_request.responseText;
}

else
{
var err = 'Error : Server returned a status code : ';
err += http_request.status;
alert ( err );
server_response = false;
}
}
};

// GET method
if ( http_method == "GET" )
{
http_request.open ( "GET", pURL, request_type );
http_request.send ( null );
}

// POST method
else if ( http_method == "POST" )
{
http_request.open ( "POST", pURL, request_type );
var post_ctype = "application/x-www-form-urlencoded";
http_request.setRequestHeader ( "Content-Type", post_ctype );
http_request.send ( pPostVars );
}

return server_response;
}

Friday, June 1, 2007

Image upload and preview without a page refresh

Whenever I am asked to develop a page where content needs to be fed without a refresh, I think of AJAX. And whenever I think of Asynchronous Javascript and XML; my stomach rolls over and my eyes bulge out !!! I've been writing web apps using AJAX for more than 2 years now; but somehow I never happen to get it right in the first shot.

So, I was sitting glumly, readying myself to drum out that javascript code; when Swapna looked across my shoulder and said,
"You don't NEED ajax for that !!!"
"Huh??? You don't?"
"No... The older technologies are good enough !!!"

Yup !!! I was as surprised as you too. Let me tell you what I learnt from her.

Suppose you want to build a simple application with an image upload functionality, and you want to display the uploaded image in the preview screen soon as it is uploaded. Now, how do you do this without AJAX? With some smart programming, of course.

Let's see how...

First, you will have to have a control which will allow you to upload the image to the server.

<form name="frmUpload" id="frmUpload" enctype="multipart/form-data" action="ImageUploadView.php?strAction=upload" target="_blank" method="POST">
<h1>Test Page For file upload and access the file on the current page</h1>
<input name="strUpload" id="strUpload" type="file" value="Select Image"><br/> <br/>
<a href="javascript:void(0);" onclick="javascript:UploadImage();">Click to upload image</a>
<br />
<br />
<img id="imgUpload" name="imgUpload" src="x.jpg">
</form>



Next, we define a Javascript function UploadImage(), that will submit to the same PHP file, but in a new window.

// description : upload the image to the server
// notes : 1. open a new window
// 2. submit the form to it

function UploadImage()
{
window.open("","upload_image");
document.getElementById( 'frmUpload' ).target="upload_image";
document.getElementById( 'frmUpload' ).submit();
}



We also define another Javascript function, whose purpose is to reset the source of the image on the current page.

// description : set the src of the image to the uploaded one
function SetImageFile( pImgSrc )
{
document.getElementById( 'imgUpload' ).src=pImgSrc;
}



The image upload request is handled on the server. At the server end, we throw Javascript code that calls the function SetImageFile().
**Please note that the script will require write permissions to the directory it's residing in.**

<?php
$imagename = uniqid('ff') . ".jpg";


// move (actually just rename) the temporary file to the real name.
// write permissions are required by the script to place the image here.
move_uploaded_file ( $_FILES['strUpload']['tmp_name'], $imagename );

print ( "<script type=\"text/javascript\">" );

if(file_exists($imagename) && $_FILES['strUpload']['name'] != '')
{
print ( "self.opener.SetImageFile(\"" . $imagename . "\");" );
}

print ( "window.close();" );
print ( "</script>" );
?>


And Viola !!! The uploaded image is displayed in the page without needing a refresh.

What are we doing here? We are -
  • submitting the FORM to the server.
  • at the server, we store the image.
  • we then print javascript which is actually calling the javascript functions residing in the parent document.
  • which then, replaces the image source.
The full code is given below. Copy the code into a file, say, ImageUploadView.php, and check it out.

<?php
// file name : ImageUploadView.php
?>
<html>
<head>
<title>Image Upload and Preview without Page Refresh</title>
<script type="text/javascript">

// description : upload the image to the server
// notes : 1. open a new window
// 2. submit the form to it
function UploadImage()
{
window.open("","upload_image");
document.getElementById( 'frmUpload' ).target="upload_image";
document.getElementById( 'frmUpload' ).submit();
}

// description : set the src of the image to the uploaded one
function SetImageFile( pImgSrc )
{
document.getElementById( 'imgUpload' ).src=pImgSrc;
}

</script>
</head>
<body>

<?php
// case : show the FORM, by default
if( !isset($_REQUEST['strAction']) || $_REQUEST['strAction'] == "" )
{
?>
<form name="frmUpload" id="frmUpload" enctype="multipart/form-data" action="ImageUploadView.php?strAction=upload" target="_blank" method="POST">
<h1>Test Page For file upload and access the file on the current page</h1>
<input name="strUpload" id="strUpload" type="file" value="Select Image"><br/> <br/>
<a href="javascript:void(0);" onclick="javascript:UploadImage();">Click to upload image</a>
<br/>
<br/>
<img id="imgUpload" name="imgUpload" src="x.jpg">
</form>
<?php
}

// case : upload the file
else
{
$imagename = uniqid('ff') . ".jpg";

// move (actually just rename) the temporary file to the real name.
// write permissions are required by the script to place the image here.

move_uploaded_file ( $_FILES['strUpload']['tmp_name'], $imagename );

print ( "<script type=\"text/javascript\">" );

if(file_exists($imagename) && $_FILES['strUpload']['name'] != '')
{
print ( "self.opener.SetImageFile(\"" . $imagename . "\");" );
}

print ( "window.close();" );
print ( "</script>" );
}
?>
</body>
</html>



Neat. Ain't it? No creating requests. No opening connections. No parsing responses. No cross-browser support headaches. No Nothing.

Just Plain Simple and Neat !!!

God give Swapna a long life !!!