Search engines such as Google, Yahoo, MSN and Ask decided on a sitemap.xml file/schema a while back.

The Sitemap Protocol allows you to inform search engines about URLs on your websites that are available for crawling.

Google – Webmaster Tools

When a website is re-indexed this sitemap.xml file is scanned for added and updated pages. For faster indexing, search engines can also be notified, or pinged, when content has been added to your website.

A plugin was made for the Mephisto Blog to generate the sitemap.xml file. That plugin can be found here.

I made a fork the mephisto_sitemap plugin and added code to ping Google, Yahoo, MSN and Ask everytime a post has been added/updated. You can find it on my Github Repository.

PHP to Ruby: Lesson 2

March 22nd, 2009

In the first lesson we went over basic similarities of Ruby and PHP. Lets go over some more.

The Basics

Its essential to know what type of data you’re working with. Whether its a string, integer or an array, we need to know what type of data we’re about to manipulate.

PHP has the following functions is_array(), is_bool(), is_integer(), is_object(), is_string(), and many more.

Ruby also provides this functionality. Remember from the first lesson, Ruby is an object-oriented language so data type checking will be done with the method is_a?. Here are some examples:

1
2
3
4
5
6
# PHP
if(is_string($var))
...

if(is_integer($var))
...
In Ruby:
1
2
3
4
5
6
7
8
# Ruby
if var.is_a? String
...
end

if var.is_a? Integer
...
end

PHP is very powerful when working with arrays. A few useful functions are array_keys(), array_values(), explode() and implode().

For Ruby, in the same order, the methods are keys, values, split and join.

1
2
3
4
5
6
7
8
# PHP
$var = array( 'my',=>1, 'php'=>2, 'hash'=>3 );

$keys = array_keys($var); # using array_keys()
$values = array_values($var); # using array_values()

$new_array = explode(' ','my php array'); # using explode()
$new_string = implode(' ', $new_array); # using implode()

And for Ruby:

1
2
3
4
5
6
7
8
9
10
11
# Ruby
var = { 'my'=>1, 'ruby' =>2, 'hash'=>3 }

keys = var.keys # using keys method
values = var.values

new_array = 'my ruby array'.split(' ') # using split method
new_string = new_array.join(' ')

# splitting a string option 2
new_array = %W(my ruby array)

Hope this was helpful.

PHP to Ruby: Lesson 1

March 14th, 2009

The very basics

The Ruby language is object-oriented. PHP is not object-oriented, but has objects. Ruby’s object-oriented nature results in some areas of it’s syntax to look very much like JavaScript. PHP’s echo is puts in Ruby. PHP uses semicolons. Ruby uses semicolons, but only in specific cases. For clean, readable code, assume you won’t be needing semicolons. Lets being…

The Basics

PHP creates arrays and hashes with the same function array().
1
2
3
4
5
6
# PHP
$array = array('my', 'php', 'array');
$hash = array(
   'my_index'=>'my_value',
   'my_second_index'=>'my_second_value'
);

Ruby handles arrays and hashes separately.

1
2
3
4
5
6
# Ruby
array = ['my','ruby','array']
hash = {
   'my_index'=>'my_value',
   'my_second_index'=>'my_second_value'
}
Read the rest of this entry