Sunday, May 9, 2010

Ajax-curl wrapper for google suggestion

When you search for something in google then google provides with the suggestion for the items related to that. It is very helpful sometimes.

This implementation does similar to this. For a given string it gets the list from the google search complete so that it can be used while searching in ones own application.

The implementation uses mootols for the UI interface.

Two variants of the implementations are :

1) Without #queries per item
2) With #queries per item
File structure :
|-- index.html [demo file ]
|-- js
| |-- Autocompleter.js
| |-- Autocompleter.Request.js
| |-- Observer.js
| |-- mootools-1.2-core-nc.js
|-- css
| |--Autocompleter.css
|-- php
|-- script.php

HTML:
|< type="text" name="q" id="suggestion">|

JavaScript:
Without number of queries :

document.addEvent('domready', function() {
var inputWord = $('suggestion');
new Autocompleter.Request.HTML(inputWord, 'php/script.php', {
'indicatorClass': 'autocompleter-loading'
});
});

With number of queries :

document.addEvent('domready', function() {
var inputWord2 = $('suggestion');
new Autocompleter.Request.HTML(inputWord2, 'php/script.php', {
'indicatorClass': 'autocompleter-loading',
// send additional POST data to get the #queries
'postData': {
'extended': '1'
},
// to remove span
'injectChoice': function(choice) {
var text = choice.getFirst();
var value = text.innerHTML;
choice.inputValue = value;
text.set('html', this.markQueryValue(value));
this.addChoiceEvents(choice);
}
});
});

PHP:
To set proxy :
change $useProxy = true
and enter the proxy details
$proxy = new Proxy("server", port, "username", "password" );

Link for the Demo

Download from here

Tuesday, April 20, 2010

PHP wrapper for bit.ly API

bit.ly is one of the sites which allows you to shorten the long URLs. This method of sharing URLs is becoming very popular these days.
Currently, bit.ly provides a full fledged API to access its features.

I have created a PHP wrapper for the api so that one can use it in his applications. The wrapper takes the url and gives the required data in an array format.

Structure of the wrapper :
bit_ly_php_api.php
|
|--- bit_ly class

Requirements :
  • curl library to be installed on the server. PHP4 and 5 has it by default. You will have to enable it. This blog explains how to enable cURL in XAMPP.
  • bit.ly login and API key. If you dont have API key register here and get your own key

To use this in your php file :
  • Download wrapper from here. Extract it and put it on your server.
  • add include ('path/bit_ly_php_api.php') in your php file
  • create bit_ly class instance (say bit)
$bit = new bit_ly('bit.ly login', 'bit.ly api key')
  • configure the proxy if needed
$bit->setProxy(host,port,username,password);


Now you can perform following operations :
  • Shorten a long URL:
$short = $bit->shortenURL('www.cse.iitb.ac.in');
$short is of type array and contains following :
$short['status']['code'] :- status code for the operation
$short['status']['text'] :- status text for the operation
$short['short_url'] :- shortened URL for 'www.cse.iitb.ac.in'
$short['long_url'] :- 'www.cse.iitb.ac.in'
$short['global_hash'] :- global hash value for the URL. This is other shortened URL :- 'bit.ly/' + global_hash

  • Expand a bit.ly URL :
$expand = $bit->expandURL('http://bit.ly/9Ty5JM');
$expand is same as $short.

  • Validate a user :
$valid = $bit->validate(login, apikey);
$valid is of type array and contains following :
It contains same status messages as $short
$valid['valid'] :- returns 1 if (login, apikey) is valid else 0

  • Set new user and api key
$bit->setLoginAndKey(login, key);
This changes the login name and the api key.

Thursday, February 25, 2010

"The 200"

It is to complement G2's poster "Sachin in 200".


If not the full movie here are the trailers.

In English :





In some other language with reviews :






The original source of the videos are 1 and 2.

Sunday, February 14, 2010

General Aptitude -- an area of controversy

As it appears, GA is very vast field, encompassing almost every thing one can think of. So are the questions of this category.
But the point of concern is what should be the solutions of these questions.While solving GA questions, often you find yourself in the position where more than one logic works. And to make the situation even worse, the options given for the question has all those.
One similar thing happened in 2010 GATE paper.

Question was :
If 137 + 276 = 435 how much is 731 + 672 ?
a) 534 b) 1403 c) 1623 d) 1513

Solution 1:
Just by looking at the numbers one notices that all of them are less than 8. So try the base 8 and it works. 137 + 276 = 435 in base 8. So answer will be 1623 for 731 + 672.

Isnt that super easy?. But wait, some people who didnt get this tried a different approach.
Solution 2 :
137 + 276 = 435
Now, reverse each number:- 731 + 672 = 534.

Well some people may come with all other logic for other options too.

But the problem is still there, what should be the correct answer? What should one answer when he is writing the exam?

Well, people say, answer should be the one which is most general of all. But this statement is itself ambiguous. How you define the general ?
Clearly, for a student of digital logic answer 1 appears more general but to others answer 2.
On various GATE forums people are having debates over this question. All types of arguments are put forward like GA is aptitude not logic, Numbers are inherently decimal not octal.
These arguments are not limited to this question only. These are questioning the scope of this limitless area.

Saturday, January 2, 2010

Send Unlimited size Free SMS via IndyaRocks

All the existing free SMS services comes with the constraint on the length of the SMS you can send. Like
  • 160by2 allows only 80 characters + 80 characters of Ads(This annoys me, so I donot use it)
  • Indyarocks allows 140 characters
So, here is a simple hack which will allow you to send unlimited size SMS via Indyarocks.
While going through the source page of the Indyarocks I discovered that it uses Client-side validation of the length of the SMS. So we will be exploiting this fact in this hack.

Step -1 -> Login to your Indyarocks account.
Step -2 -> Go to the Send SMS page.
Step -3 -> View the source code of the page (Ctrl + U or View->Page Source).
Step -4 -> Save it on your system with html extension(say sms.html).
Step -5 -> Open sms.html in text editor.
Step -6 -> Search for function chngcnt. It is a JS function. Look for the number in the if conditions of this function. It will be 130 or 140, change this to some high number say 9999.
Step -7 -> Search for function sendfreemsg(). Do same here too, change 140 to some high number.
Step -8 -> Copy the address from your address bar of the indyarocks page(leaving sms.php). In my case it is http://www.indyarocks.com/mvas
Step -9 -> Search for send_msgs.php in the sms.html and append http://www.indyarocks.com/mvas to it in the front, so that it becomes http://www.indyarocks.com/mvas/send_msgs.php
Step-10-> Now open sms.html in the browser and send the SMSs

In this, the javascript utilities like address from phone book doesnot work. To enable them correct the link to .js files by adding http://www.indyarocks.com to the address.
Also, this works only for the SMS to Non-members option of Indyarocks.
Now, you can use this page whenever you need to send the SMS. You will only be needed to login to your Indyarocks account in another tab. (Site doesnot uses any local session variables, another demerit of the website).
Happy SMSing in New Year

Saturday, September 26, 2009

My First Hack into Netbeans

This post describes how to develop a simple macro for Netbeans to comment and uncomment the selected text. By default the purpose is done by a inbuilt template in Netbeans. To comment the selected text using this template follow :
  • Select the text to be commented.
  • Press Alt+Enter. A drop-down menu will come. Select Surround with /*$selection*/
This method becomes cumbersome when you keep adding your own Templates.(How to develop your own Template in another post :P ) NetBeans allows you to develop your own macros to perform such tasks.
  • Go to Tools -> Options.
  • In Options select the Editor -> Macros tab.
  • Now Click New. A pop-up will come. Enter the macro name Comment .
  • A new entry in the macro table is entered. Select the entry and paste the following code in the Macro Code window.
select-identifier cut-to-clipboard caret-begin-line insert-break "/*" insert-break delete-previous delete-previous paste-from-clipboard insert-break remove-line "*/" insert-break
  • Set Shortcut Alt+Q (or anything you like)
Comment macro is created. Similarly create uncomment macro. Paste following code in the Macro Code window:
select-identifier last-non-white remove-line cut-to-clipboard caret-begin-line paste-from-clipboard first-non-white remove-line remove-line
  • Set shortcut Shift+Alt+Q (or anything you like)
  • Click Ok.
Now both the macros are created. To use them Select the text from the editor and press Alt+Q to comment and press Shift+Alt+Q to uncomment the commented code. Here is the list of elementary macro functions. You can develop your own using these link.

Enjoy NetBeans :)

Wednesday, September 16, 2009

Multiuser Gtalk

You can customize Gtalk to allow multiple login from a computer.
All you have to do is to goto the installed gtalk.exe or goto Start Menu right click Gtalk -> Properties
add /nomutex to the Target.

Now restart Gtalk. You can run multiple instances now.