Tuesday, January 20, 2009

my quest for the greatest linux distro

Well, I can't tell that I found THE linux distro, but I tried Ubuntu and OpenSUSE and their performance can't match with Linux Mint (Xfce) on my three year old laptop. Linux Mint is Ubuntu-based, so we got the advantages of Ubuntu which's Debian-based and it is lightweight thanks to Xfce which is a desktop environment lighter than gnome (should I compare with Kde?). Furthermore, Linux Mint is user-friendly and I think that it is a good distro to start your linux adventure.

Friday, January 16, 2009

read attached pdf without acrobat reader

gmail pdf Thanks to Gmail's new service, it is possible to read PDF files attached to e-mails without the need of saving them and opening them with Acrobat Reader. I tried the new feature and it worked flawless as long as I could test it. As you can see in the picture, all you have to do is to click on "view" to read the PDF file.

Monday, January 12, 2009

create short urls

Sometimes it is quite handy to use a shorter url instead of a long one. Why you have to type http://java.sun.com/javafx/faqs.jsp instead of http://abe5.com/c43?
There are several websites that offer this short url generation service for free. TinyURL is one of the most populars, but I'd recommend Abe5 that offers shorter urls.

Sunday, January 4, 2009

custom search in maxthon 2

Maxthon is my favorite internet browser and one of its greatest features is the custom search ability. You can run a search in (almost) any site just by writing your query to the address bar and hitting enter. Let's see how it is done.

Go to the website in which you'd like to search your query. In our example, the website is mininova which is a torrent search engine.


Write an arbitrary query to the search box. We use "Queen" as query. Then, hit the search button.

mininovaNow that the search results are in hand, take a look at the address bar.



mininova


You can see that "http://www.mininova.org/search/?search=Queen" is written in the address bar. This means that, for running a different search all we have to do is changing the word "Queen" with the new query (e.g. http://www.mininova.org/search/?search=Savatage) and hit enter to load the new url. But there is an easier alternative that'll automate our search so we won't have to write that long url everytime we want to search a torrent.

Now open maxthon > tools > maxthon setup center and choose search tab and click on "add item". You'll see a row like this:

mininovaFirst textbox is the title. You can choose something arbitrary. I choose "Torrent" in our example. The second textbox is alias. We will choose an alias for the search engine which will reduce the necessary amount of typing. I choose "t" (for torrent). So I will be able to do a custom search with the syntax "t myQuery". The third one is the url that we discovered in previous steps. It was "http://www.mininova.org/search/?search=Queen" for our example. We will replace our example query by "%us" which will give us http://www.mininova.org/search/?search=%us
in our example. I replace "Queen" with "%us" and write the new url in the corresponding textbox and then click on save.

mininova

Now, you can search a torrent by writing "t Query" to the address bar and hitting enter. Bon appétit!

Friday, January 2, 2009

useful stuff about associative arrays in javascript

Associative arrays in javascript have a similar task to associative arrays in any programming language; holding key-value pairs. If, for instance, our "keys" are fruits and the "values" associated to these keys are fruits' count in the basket then fruitBasket which holds these keys (fruits) and values (fruits' count) is the associative array.

First let's see how an associative array is created;


var fruitBasket = new Array(); /*create it just like any other array*/


Then let's populate our fruitBasket with different types of fruits


fruitBasket["apple"] = 1; // there are one apple
fruitBasket["orange"] = 3; // three oranges and
fruitBasket["lemon"] = 2; // two lemons in our fruit basket


Now, let's retrieve the value associated with a key. For instance, let's retrieve and print the count of "apple".


document.print(fruitBasket["apple"]);


I'm interested in the whole content of my fruitBasket. I want to print it. But how can I retrieve it? Assuming that the keys of the associative arrays are objects (fruits of type String in our example), it is quite easy to guess that we can't access them the way we did with plain arrays. So fruitBasket[0] won't return me the first fruit in the basket. Let's see how we can accomplish it.


for(var fruit in fruitBasket){ /*for each key in the associative array*/
// write the key (fruit name)
document.write(fruit+"=");
/* write the value associated with the key (fruit count)*/
document.write(fruitBasket[fruit]+", ");

}


Now, allow me to complicate things a little bit. I throw two more apples and three more lemons in the basket. So we have to add 2 apples and 3 lemons to the corresponding counts. Let's accomplish it using our fruitBasket.


/* fruitBasket["apple"] returns the value associated with the key "apple" which is its count in the fruitBasket. */

fruitBasket["apple"] = fruitBasket["apple"] + 2; // add 2 to the actual count
fruitBasket["lemon"] = fruitBasket["lemon"] + 3; // add 3 to the actual count


I want to add a new fruit type to the basket, but first I want to check if it is really a new fruit or an existing one in the basket. Assume that I want to add 2 bananas to the basket.


/*
I try to retrieve the value associated with the key "banana". If there's no such a key then it'll return "null".
*/
if( fruitBasket["banana"] == null ){ // no banana in fruit basket
/* create a banana key and give it 2 as value, that is, add 2 bananas to our fruitBasket*/
fruitBasket["banana"] = 2;
}


To sum up, I tried to show how an associative array is created, how its key-value pairs should be retrieved and how to add new key-value pairs to the associative array.