Enabling telnet in windows vista

Some of you may be missing the good old command-line telnet client. The thing is that vista has this client disabled by default. The good news is that you can easily install/enable it. To do so, follow these steps:

  1. Go to Control Panel
  2. Click on ‘Programs’
  3. Under ‘Programs and Features’, click on ‘Turn windows features on or off’
  4. Wait a bit for the list to be compiled
  5. Tick ‘Telnet client‘ and hit ‘OK’ then wait for it to be installed

You may now open a command prompt and use telnet hostname port

Good luck

Konami Code

The ‘Konami code’ fad is back!

For those of you who don’t know, Konami code (a.k.a Konami Command) is a cheat code that was used in several games back in the day.

It has been introduced not long ago on several websites. Upon entering this cheat code, some ‘secret’ is revealed or a page is unlocked.

The sequence is: Up, Up, Down, Down, Left, Right, Left, Right, B, A

Some of the famous websites that make use of it are: digg.com, facebook.com
For instance, hitting the above sequence on any story page on digg would change the way comments are displayed, and you’ll be able to view them in a tree/nested structure.
facebook would simply display some joyfull circles/colors (hit any key or press the mouse button after entering the konami code)

Traffic forwarding on linux using IPTABLES

IPTables allows you to easily setup rules for packet filtering/forwarding.

So, to keep it short and simple: assume you’d like to forward any traffic coming to your machine ( on port 80 to machine2 ( on port 8080 then:

– Enable port forwarding:

echo 1 > /proc/sys/net/ipv4/ip_forward

– Now add the rules:

iptables -t nat -A PREROUTING -p tcp -d –dport 80 -j DNAT –to

iptables -t nat -A POSTROUTING -d -j MASQUERADE

The -p tcp flag specifies that the protocol is TCP (as opposed to UDP, ICMP for example).

The -d flag specifies that the packets was destined to IP

The –dport 80 means that the packet had port 80 as destination

-j is the target of the rule being enforced, NAT (network address translation). In more advanced rules, one can specify a predefined iptables chain of rules.

–to will specify to where this packet should be forwarded, and on which port

As for the second rule, it says that outgoing packets to the second machine should be masqueraded. In other terms, the user trying to access the original machine on port 80 will not have a feel that his request was forwarded. The packet will show up as if it came from the masquerading host, while in practice, the request was forwarded to machine2, and the reply came back from that same machine.

On a side note, make sure to add these iptables rules to a file, give it an execution permission (chmod +x /path/to/file), and add it to /etc/rc.local so that it is executed on every system boot. Otherwise, the above rules will be fliushed every time your system is restarted.

Google’s source:life

One of the neatest recent additions to Google search is the LIFE photo archive.

Basically, google images is now indexing a large photo archive owned by the famous Life magazine. Many of these images were also never published before. Talk about a jump back into some of the finest moment in history. Some of these photos date back to around the 1750s.

To search this archive for a specific keyword, simply append the following to your search term(s):  source:life

Try some of the following searches for instance:
BluesTitanicGold rush
You may also browse through the decades-categorized items on the official landing page

Simply, amazing!

Google search tips

‘Face’ photos
When searching for images, you could narrow down your search to ‘faces’. Simply, append ‘&imgtype=face’ to the end of the google images search url.
So if you’re searching for Robert De Niro, try doing it with ‘face’ as image type

File Types
You could specify the type of file you’re looking for. Simply append ‘filetype: type’ to your search query. So if you’re looking for an excel file related to subject Foo, then search for: ‘Foo filetype:xsl’

Site limitation
If you’d like to narrow down your search results to those coming from a certain website, you may use the ‘site:’ feature. For instance, if you’re looking for new year related articles on cnn.com, search for: ‘new year site:cnn.com’

Are you looking for a quick definition of a certain word, abbreviation, etc? use google’s ‘define:’ criteria. For example, if you’re not sure what AFAIK means, simply search for: ‘define:AFAIK’. A set of definitions from multiple glossary website will be returned.
Note that you may do so for multiple languages

Cached version
Looking for a quick way to see google’s cache of a certain page? simply search for ‘cache:url’. For example, searchfing for ‘cache:cnn.com’ would return google’s latest cached version of the cnn.com page

You may easily resort to converting units in google! try searching for some of the following: ’12 feet in meters’, ’10 kilograms in pounds’, ’20 degrees celsius in fahrenheit’.
You may also resort to currency conversions (not lively updated as it seems), e.g. ’24 euros in usd’

On a note similar to that of the conversions, you may do simple to medium mathematical calculations using google as well. Try searching for sin(50), cos(39), tan(82)*24/cos(41). Quite neat.

Current time
You can easily find the local time in a given city. Simple use: ‘time in cityname’. For instance, trying ‘time in kuala lumpur’ can return at the time of testing: 10:32am Saturday (MYT) – Time in Kuala Lumpur, Malaysia

Weather forecasts have never been easier. Try searching for ‘Weather in Prague’, ‘Weather in Rio de Janeiro’. You’d get a 4 days forecast (including today), with high, low and cute descriptive icons.

Yes, google does help you get quick stock quotes as well! simply search for ‘stocks:stockname’. e.g., searching for ‘stocks:dji’ will return the Dow Jones Industrial Average, along with open, high, low, last update time and simple activity graph!

Movies show times
Google allows you to search for movies show times, by ZIP codes. So for instance, if you reside in Beverly hills 90210, try searching for: ‘showtimes 90210’

Page titles
Looking for web pages that contain a specific set of terms? you may query google using the following method: ‘intitle: “sentence here”‘, e.g. ‘intitle: “dude where’s my car”‘

You may let google search not only for terms you enter, but also their synonyms. For instance, if you’d like to find website that list inspirational quotes, with whatever synonyms inspirational might have (such as motivational), try looking for: ‘~inspiring quotes’ (by adding the tilde as a prefix to the terms in question)

Recovering your Journalspace.com blog posts

So it seems that journalspace.com is gone for good. For those of you that used to have blogs hosted there, now is the right time to try to recover as much of your blog posts as possible.
Definetly, the only resource that one can think of is search engine cache. Andrew heart seems to have already mentioned this, but let me emphasis on some tips and tricks while doing your search.

Recovering journalspace.com blog posts using google

* To search for all your blog’s cached pages, use:


* If there are lots of indexed pages and you’re looking for a specific post, use:

site:yourusername.journalspace.com intitle:”your post title

The quotes around your post title means that the post title contains that exact phrase. If you’re unsure of the exact title, but remember a couple words from it, you can use:

site:yourusername.journalspace.com intitle:word1 intitle:word2 intitle:word3

* If you’re looking for a specific category page on your blog, use:

site:yourusername.journalspace.com inurl:cat

* If you’re looking just for entries, not general pages and category pages, use:

site:yourusername.journalspace.com inurl:entryid

* If you’re looking at posts with comments, try using:

site:yourusername.journalspace.com inurl:displaycomments

* If you’re looking for a list of posts from a specific month, use:

site:yourusername.journalspace.com inurl:”m=0” inurl:”Y=0000

replacing the dummy zeros with the month and year value

* If you’d like to recover your profile info, use:

site:journalspace.com/profile/ inurl:yourusername

replacing yourusername with your actual username.

* If your blog had authors/contributors and you’re looking for posts from a specific one, use:

site:yourusername.journalspace.com inurl:author inurl:TheAuthorName

Obviously, replacing TheAuthorName with the used author name.

* If you’re looking for all blog entries that DO NOT match a certain term in their title, use:

site:yourusername.journalspace.com -intitle:termToDisregard

Note that if you want to exclude some term(s) from all the result (i.e. not just found in the title), use:

site:yourusername.journalspace.comtermToDisregard1 -termToDisregard2 -termToDisregard3

* If your’d like to see thumbnails of images on your blog that google has cached, go to:

http://images.google.com/images?um=1&hs=uR5&q=site%3Ajournalspace.com+yourusername&btnG=Search+Images (replace yourusername)

The image cache is not for the full size images, but this might help you remember which photos you uploaded, and you may discover you you still have them somewhere on your drive!

Recovering your items using MSN live search or Yahoo! site explorer

Google is not the sole search engine indexing content. So if there is an item on your blog that google did not cache (and it’s very possible), try searching for the missing content on other search engines.
MSN Live is one other good example, with search keywords almost identical to that of google.

The URL is http://search.live.com
Useful Keywords you could use are intitle:, site:, – (negating a word), “” (quotations, to search for exact terms). Though, not sure about the alternative to google’s inurl

Yahoo! site explorer is at http://siteexplorer.search.yahoo.com/
‘Exploring’ your blog can be done at http://siteexplorer.search.yahoo.com/search?p=http%3A%2F%2Fyourusername.journalspace.com%2F (replacing yourusername with your actual blog username). A link to each of the pages’ cached copy is available

Keep in mind that search engines will eventually de-index their cache, once the pages in question will be found to be no longer available. So, act quickly on recovery.

Right now, Google has 53.2K pages, and 375 images indexed.
MSN Live has 12.5K pages and 23K images indexed.
Yahoo! has 2.3K pages and 536 image thumbs.
I wonder if these are normal numbers or did the search engines start deindexing?

MySQL password hashing

Whenever you upgrade your MySQL installation, make sure to upgrade any client that uses it.

In some cases, clients that use a version prior to 4.1 will have a problem authenticating against the MySQL database if the latter has a post 4.1 version.

The trick is that after 4.1 (i.e. 4.11 and up), MySQL changed the way it stores the passwords in the user table inside the mysql system database.
Password hashes are now 41 bytes long instead of the old 16 bytes.

So for example, if your MySQL server is 5.0, while your php-mysql library is 4.1, your web applications will fail to connect to the database. As such, it is recommended that you upgrade the client.

In any case, MySQL offers a way to change the hash back into the old format. For the sake of argument, assume the user in question is john, and you want to be able to connect using password dummy. In this case, connect to your MySQL server from the prompt (SSH and use ‘mysql -u root -p mysql’ on linux, or go to your mysql/bin windows directory and execute the same query), then issue the following queries:

update user set Password=OLD_PASSWORD(‘dummy’) where User=’john’;
flush privileges;

the OLD_PASSWORD() function will generate the old 16 bytes hash. The first query will eventually update the user password to use this hash. The second query is necessary in order for the MySQL service to re-read the new user privileges.

PS: if your root password is not working, refer as well to the guide on resetting it.

Alternatively, if your database has many users and you didn’t keep track of them, you can use the following query and it will return usernames that are using the new hash

select distinct(User) from User where LENGTH(Password)!=41;

Getting rid of the ^M characters in vi

If you’re a regular vi user, you may have noticed that some files, when being edited in vi, contain ^M characters at line ends.

This usually happens when you edit a file using certain windows-editors, then transfer it to your *nix machine.
Luckily, it is easily to get rid of this control character. While in vi, execute the following command:


Important note: do not manually type a caret then the capital M character. Actually, in order to type ^M, press CTRL+V followed by CTRL+M.

A quick note:  the above command will look for the ^M character starting on line 1, substituting it ($s) with nothing (thus having the two consecutive forward slashes / with nothing in between). And this substitution is performed globally (g).

Google Chrome tips

Useful keyboard shortcuts:

  • CTRL+T: Open new tab
  • CTRL+W: Close tab
  • CTRL+N: New window
  • CTRL+U: View page’s source code
  • CTRL+J: File download history
  • CTRL+SHIFT+N: Incognito window (no traces in the browser history or cookies)
  • SHIFT+ESCAPE: Google Chrome’s Task Manager (can kill tabs, etc)
  • CTRL+E or CTRL+K: perform a Google search for term(s) you provide
  • CTRL+TAB: Browse through tabs (forwards)
  • CTRL+SHIFT+TAB: Browse through tabs (backward)
  • CTRL+D: Bookmark current page
  • CTRL+F or F3 or CTRL+G: Search current page & highlight search terms (you can move through term occurences by using CTRL+G (forward) or CTRL+SHIFT+G (backward))
  • CTRL+H: View history
  • CTRL+R: Refresh
  • CTRL+L: Highlight address bar
  • CTRL+B: Show/hide bookmarks bar
  • CTRL+SHIFT+J: Code inspector
  • CTRL+SHIFT+L: JavaScript debugger
  • CTRL+SHIFT+B: Bookmark manager
  • CTRL+(+) / CTRL+(-): Increase / decrease font size
  • CTRL+5: Takes you to the 5th tab directly (replace 5 but your desired tab number)
  • ALT+Home: Opens the Chrome ‘home’ page in a new tab

To view some useful browser-recorded data, type one of the following in the address bar:

about:stats (counters/timers)
about:cache (what the browser has stored in its cache)
about:memory (useful to see which tab/window is consuming most memory)
about:dns (domain name resolution related data)
about:network (VERY useful. For instance, if some tabs are loading content, you can track what pages, files are being fetched)

– You may jump backward (or forward) through the tab’s history by holding down the backward (or forward) arrow on the address bar.
In other terms, you can view the previous URLs a tab has been through and chose one of them, instead of looping sequentially (clicking the back button several times)

– You may perform simple mathematical calculations without opening your calculator! Simply, type it in the address bar. e.g. typing 21.5 / 3.2 (with spaces) would yield the 6.71875 result WITHOUT havint to press RETURN/ENTER.
You could use this same method to do conversions. e.g. typing ’43 miles in km’ and waiting for a second would return  69.201 miles. Quite neat.

– You may resize text areas you stumble upon on web pages. Simply, click and hold the bottom right corner of the box and voila!

– You may detach a tab by dragging it into your Desktop. This will change this tab into a brand new Chrome window!
Alternatively, you may ‘attach’ a tab to another Google chrome window by dragging it from one window to another.
In other words, if you have 2 Google Chrome windows open, you may move a tab from the first instance to the second.

Setting up MySQL database replication

It’s always about data. What’s the use of any system without the data it relies on?

Setting up a database replication is one of many steps that should be taken in order to preserve data, preventing any loss and making disaster recovery easier.

Luckily, it’s easy with MySQL. So let’s suppose we have two servers running MySQL, one called host1 and the other host2.
Replication can be either master-master or master-slave. With a master-slave replication, the slave always replicates what the master database is executing. In master-master replication, both databases synchronize with each others.

For the purpose of this tutorial, a master-slave (here host1 and host2 respectively) scenario is examined.

First of all, open the mysql config file on host1 (usually found at /etc/my.cnf on linux, and c:\windows\my.ini on windows), and uncomment (remove the hash of) the following line:


Secondly, you need to specify the file where the master (host1) should log (write) the queries it’s executing. This will enable the slave (host2) to read these queries and execute them as well. As such, add a line such as:

log-bin = /path/to/mysql-bin.log

where the value above is the path to file where MySQL should be doing the logging. You could very well create a separate directory or use the default mysql installation directory (such as c:\program files\mysql\ on windows or /var/lib/mysql on linux)

Then, you need to specify the name of the database in question. So if you’re setting up replication for one of your MySQL databases called ‘work_data’, then, this is the line you need to add to your MySQL config:

binlog-do-db = work_data

Finally, you need to specify a server id, which says that this is the master server


Save the config file and exit.
Now you need to give host2 the permission to replicate the data. As such, a MySQL query needs to be issued on the master.

So on host1, login to the MySQL prompt (mysql -u root -pyour_root_password) (or PHPMyAdmin, etc… whatever you use), and issue the following statement:

grant replication slave on *.* to ‘username’@’%’ identified by ‘password’;

Make sure to replace username and password with a credential of your choice. Do keep the single quotes though.
The % sign means that the slave can connect from any host. If you want it to be more secure, replace that with host2 (the slave’s hostname).

After all the above is done, restart the MySQL service (service mysqld restart (linux) or, net stop mysql, net start mysql (on windows)).

If the database had data earlier, make sure you dump it and load it on the slave before doing any of the above. Dumping data is easy and can be done by cd’ing to the MySQL bin directory and issuing:

mysqldump -Q -u root -pyour_root_password databasename > database_dump.sql

(replace the password and database name with the correct login). The whole database will now be in the file called database_dump.sql

To import it on host2, cd to the mysql bin directory and issue:

mysql -u root -pyour_root_password databasename < /path/to/the/file/database_dump.sql

The MySQL config file on host2 should have the following lines:

master-host = host1
master-user = username
master-password = password
master-port = 3306

where host1 is the master’s hostname/IP, and username and password are the credentials you used when granting replication access a few steps above. 3306 is the port MySQL is running on (which is the default)

Then start the slave process on host2 by issuing at the MySQL prompt:

start slave;

To make sure replication is working, issue the following SQL query on host1:

show slave status \G

(Slave_SQL_Running and Slave_IO_Running should report ‘Yes’)

Good luck