Saturday, November 20, 2010

GPS coordinates and Google Maps

Many times we require to extract the GPS coordinates from a Google Map location. Similarly we might need to pinpoint an exact location in Google Map with knowledge of GPS coordinates obtained from a GPS device. This articles demonstrates how you can use GPS coordinates with Google Maps.

Suppose you are using your favorite GPS device and have located an interesting place to share with your friends. Once ytou record the GPS coordinates with your GPS device, you can easily share the location with your friends by mapping the GPS coordinates on Google Maps. Just go to the following URL:

http://maps.google.com/?ll=LATITUDE,LONGITUDE

, substituting the LATITUDE and LONGITUDE above with the ones you obtain from the GPS device. For example I am currently writing this article from coordinates  (35.892944,14.460829), and you can easily find this location on Google Maps by visiting http://maps.google.com/?ll=35.892944,14.460829:


If on the other hand you are given a location on Google Maps and you want to record it on your GPS device, you need to extract the GPS coordinates from Google Maps. This is a very easy thing to do and all you need is to type the following javascript code in the address bar of your browser while you are still on the Google Map page:

javascript:void(prompt('',gApplication.getMap().getCenter()));

So for example, if you were to extract the GPS coordinates from the previous example, load the Google Map and enter the javascript code:

Basic Apache Rewrites

URL rewriting is a powerful technique not just for the Webmasters, but also for the SEO and Security guys. This article will give an overview towards the most common ways to implement rewrites using the Apache mod_rewrite.

A basic rewrite will look like this:

RewriteRule ^(.*?)/abc(.*) $1/def1$2 [R=301]



So for example if you try to access  http://www.r00tb0x.com/abc123/whatever you will be redirected to http://www.r00tb0x.com/def123/whatever.

The R=301 flag tells Apache that the rewrite is a Permanent (301) Redirect. Furthermore, $1 substitutes the first regex pattern, $2 the second regex pattern, and so on.

If you want to redirect specific requests made by Googlebot or Bingbot (the crawlers used to index pages on Google and Bing search engines), you can use the following code:


RewriteCond %{HTTP_USER_AGENT} .*(Googlebot|Bingbot).*
RewriteRule ^(.*?)/abc $1 [R=301]



This is useful if you want to omit specific pages from being indexed (such as administrator or user profiles). In this case if Googlebot or Bingbot try to access http://www.r00tb0x.com/abc they will be redirected back to http://www.r00tb0x.com.

Another popular use of URL rewriting is to make SEO friendly URLs. As you may know, websites in the form http://www.r00tb0x.com/?page=123456 are not ranked properly by Google as they lack keywords. A more SEO friendly URL would be http://www.r00tb0x.com/content/apache-rewrites-101 since the URL name contains keywords specific to the content of the page. In order to convert URL variables to SEO friendly names, one can use the following code:

RewriteCond %{QUERY_STRING} ^uuid=123$
RewriteRule ^(.*?) $1/123? [R=301]




This will redirect requests from http://www.r00tb0x.com/?uuid=123 to http://www.r00tb0x.com/123

Monday, November 15, 2010

Insert a repeated line in a text file with awk

System administrators, DBAs, network gurus, and perhaps developers, often feel the need to insert a particular word or phrase every 'x' number of lines in their script. For example a DBA might have a list of insert statements and needs to place a commit line every ten lines. This would be quite a burden to do it manually for a large script. Worry not! With awk you can easily do it like this:


awk 'ORS=NR%10?"\n":"\ncommit;\n"' db_patch.sql


This example will insert the text commit; every ten lines for the document db_patch.sql. More awk examples will follow on our website.

Find recent large files in Unix

One morning you log into a Unix server and find that one of the disk partitions is filled up. You wonder why, or perhaps, what caused it to fill up recently? The answer to this question is just a piece of cake.

Fire up Bash or your favorite shell and enter the following in the terminal:

find /home/r00tb0x/ -type f -mtime -2 -exec ls -ltrh "{}" ";"

This tells Unix to find all files (nodes of type 'f') which have been modified (created or appended to) in the last couple of days. The output will be sorted in chronological order with human readable format of the size field.

Similarly you can find old files by giving the mtime argument a positive value.

Tuesday, November 02, 2010

Syntax Highlighting + CKEditor in Drupal

This article is aimed for those users who use CKEditor to update their Drupal powered website. If you include lots of code snippets or program listings in your articles, then you might consider reading this post to improve the reader's experience.


I recommend the module Syntax Highlighter which can be downloaded from Drupal. This will enable you to format code similar to the screenshot, and has syntax highlighting capabilities supporting a multitude of different programming languages!

Once you install this module by putting it in Drupal's modules directory, you will need to install a plugin which enables you to use the Syntax Highlighting module with CKEditor. This plugin can be downloaded from here and to install you simply need to extract the source directory (located in the downloaded archive) inside modules/ckeditor/ckeditor/plugins. Next step is to configure the plugin. Open up the file modules/ckeditor/ckeditor.config.js and add the following lines of code:

config.extraPlugins += (config.extraPlugins ? 
',syntaxhighlight' : 'syntaxhighlight' );
 
config.toolbar_DrupalFull = [
  ['Source'],
  ...
  ['DrupalBreak', 'DrupalPageBreak','Code']
];

The first part of the code enables the module, while the second part adds the Syntax Highlighting button.
In theory this should work and you are ready to use this feature, but in practice most users either don't have the button or else no code formatting takes place. Therefore, make sure you read these
two important steps:

1. Make sure that you are using the DrupalFull toolbar (not the Basic or the Full). To enable go to admin/settings/ckeditor/edit/Advanced and change the settings as follows:
2. Make sure that you are using the FullHTML input format filter and not the FilteredHTML filter. To enable go to admin/settings/filters and change the settings as follows:

How to take screenshot in Macbook

Whether taking a shot of the entire screen or just a screenshot of an area, is a fairly easy task to do on a Macbook. Unlike in Windows, the screenshot is directly saved to disk rather than in memory...

To take a shot of the entire screen simply press the Command + Shift + 3 Keys. To take a shot of a rectangular area simply press the Command + Shift + 4 keys and adjust the size and location of the highlighted area by dragging the cursor.