It's been a long time coming.

February 01, 2010  |  Posted in: Life on the Internets  |  0 comments

Dear Google Apps admin,​

In order to continue to improve our products and deliver more sophisticated features and performance, we are harnessing some of the latest improvements in web browser technology. This includes faster JavaScript processing and new standards like HTML5. As a result, over the course of 2010, we will be phasing out support for Microsoft Internet Explorer 6.0 ​as well as other older browsers that are not supported by their own manufacturers.

We plan to begin phasing out support of these older browsers on the Google Docs suite and the Google Sites editor on March 1, 2010. After that point, certain functionality within these applications may have higher latency and may not work correctly in these older browsers. Later in 2010, we will start to phase out support for these browsers for Google Mail and Google Calendar.

Google Apps will continue to support Internet Explorer 7.0 and above, Firefox 3.0 and above, Google Chrome 4.0 and above, and Safari 3.0 and above.

Starting this week, users on these older browsers will see a message in Google Docs and the Google Sites editor explaining this change and asking them to upgrade their browser. We will also alert you again closer to March 1 to remind you of this change.

In 2009, the Google Apps team delivered more than 100 improvements to enhance your product experience. We are aiming to beat that in 2010 and continue to deliver the best and most innovative collaboration products for businesses.

Thank you for your continued support!

Sincerely,

The Google Apps team

Email preferences: You have received this mandatory email service announcement to update you about important changes to your Google Apps product or account.

Google Inc. 1600 Amphitheatre Parkway Mountain View, CA 94043

Array.prototype for fun and profit

January 14, 2010  |  Posted in: Programming  |  1 comments

Was listening to the StackOverflow podcast during a walk the other day. Joel was describing the tests he gives to prospective Fog Creek employees. He mentioned one, which went something along the lines of:

Take an array of numbers, find a number within the array and see if the sum of the numbers before that number and after it are equal.

So I was walking down the street listening and it seemed like an interesting question. After all, I’m always trying to better myself as a mammal. I figured it would be easy to do in Python with some list comprehensions. Then I tried to do it in my head in JavaScript while I was walking, which nagged at me enough so that I sat down to figure it out when I got home.

JavaScript 1.5 doesn’t have a built-in Array function that will pluck an element and return its index (see ECMAscript 1.6 for that), but you can create one with prototypical inheritance:

Array.prototype.has = function(v) {
    for (var i = 0; i < this.length; i++) {
        if (this[i] == v) return i;
    }
    return false;
}

I picked that up on Jonathan Snook’s blog when I was googling about to see if JavaScript had an equivalent function to PHP’s array_search (So yeah, I would have failed the code test since I Googled part of it, but I still learned something.)

Now that I could get the array key of the element in question I could write another function to return the sum of all the numbers in an array:

Array.prototype.sum = function() {
    var sum = 0;
    for (var i = 0; i < this.length; i++) {
        sum = sum + this[i];
    }
    return sum;
}

This is one of the reasons I like JavaScript, you can build-up on the language quickly. I’m already pretty familiar with most of the array functions in JavaScript, so I could use Array.slice() to do some more work for me. I wasn’t sure if the first array should include the plucked number or not, so I just included it. So let’s string it all together:

/**
 * pull element from array and return index
 */ 
Array.prototype.has = function(v) {
    for (var i = 0; i < this.length; i++) {
        if (this[i] == v) return i;
    }
    return false;
}

/**
 * Return sum of numbers in array
 */ 
Array.prototype.sum = function() {
    var sum = 0;
    for (var i = 0; i < this.length; i++) {
        sum = sum + this[i];
    }
    return sum;
}

/**
 * Simple test array
 */
var test = [4 ,3 ,2 ,1 ,0, 6, 0, 1, 2, 3, 4, 6];

var index = test[test.has(6)];                      // return index of 6
var first = test.slice(0, index);                   // grab [4,3,2,1,0,6]
var second = test.slice(index + 1, test.length);    // grab [0,1,2,3,4,6]

if (first.sum() === second.sum())
{
    console.log('the two halves split by ' + index + ' are equal' + first.sum() + ' | ' + second.sum());
}
else
{
    console.log('the two halves split by ' + index + ' are NOT equal: ' + first.sum() + ' | ' + second.sum());
}

I’m also trying to learn about proper Unit Testing, so I reckon over the next day or so I should write a proper test for this.

The more I look at it though I see a few issues. First off is that Array.has() returns the first instance of a found element. There are two 6s in my test array, so I’m only getting the key of the first one and operating from there. How should duplicates be handled?

Ruby to the rescue

December 04, 2009  |  Posted in: Programming  |  0 comments

I got a request from a client today. They had a site, that was made up mostly of static html pages (with a smattering of PHP and a WordPress blog.) They wanted to drop <meta> description tags into their site. Excellent idea. They helpfully sent along a Word doc containing the urls of each page and the description they would like added. Of course, this was a list of 30 discreet urls, which would be something of a pain to do by hand with ctrl-v/c. Like most humans I hate repetitive tasks like this, so I figured I should write a script to do it for me.

Luckily for me the url’s mapped to the html/php files themselves (no fancy routing) and looked something like this:

http://www.someurl.com/ourproducts.html  This page is about wonderful unicorns that enable your business to churn out molten rivers of gold

http://www.someurl.com/aboutus.html  We're a gang of very exciting entrepreneaurs making fabulous widgets in our Elven caves.

(etc.)

This gave me an idea: I could export the word doc to plain text and write a script to parse said textfile grabbing filenames & descriptions. The script would then open the correct files and drop the correct <meta> tags into them.

Pre-processing

To make my life easier I pre-processed the textfile with TextMate (any text editor will do) and used a find/replace to convert the urls into just the filenames wrapped with some tokens. So http://www.someurl.com/ourproducts.html became @ourproducts.html@. Wrapping the filenames with @’s made it easier to differentiate the filenames from the descriptions.

I then used TextMate’s Find in Project command to add an empty <meta type="description" content=""> tag to every file. Again, I did this to make it easier to place the descriptions later with my script. To pull this off I wrote a regex to find the <title> tags on each page and added the empty <meta> after them:

find: <title>(.*?)<\/title>

replace: <title>$1<\/title>\n<meta type="description" content="">

Ruby to the rescue

I’ve been playing around with Ruby and Python lately, to expand my horizons past PHP. I decided to use Ruby for this particular task. The following script opens my textfile and reads it line by line grabbing filenames and descriptions. It then attempts to open the file specified, finds the empty <meta> tags and drops in the description using gsub!.

I ran it from TextMate with command-R but I could have added a shebang and run it from the cli. It worked like a champ:

# Open a file and look for the empty meta tag
# if found, drop the description into it

def get_and_open_file(filename, desc)
  begin
    if f = File.open(filename, "r+") # open the file
      lines = f.readlines

      # for each line in the textfile build a new meta tag
      # and drop it into place

      lines.each do |it|
        newline = '<meta type="description" content="'+desc+'" />'

        # replace empty meta tag with loaded tag

        if it.gsub!(/<meta type="description" content="" \/>/, newline)
          puts it
        end

      end
      f.pos = 0          # back to start
      f.print lines      # write out modified lines
      f.truncate(f.pos)  # truncate the file to its new length & save
    end
  rescue

  end
end

# Open the textfile and parse it line by line looking for 
# URLs & descriptions with a regex: /\@(.*?)\@(.*)/

File.open("Metadata.txt").each { |line|
  if line =~ /\@(.*?)\@(.*)/
    filename = $1
    desc = $2
    get_and_open_file(filename, desc)
  end
}

I know its the not the prettiest Ruby code (and I’m sure I could have done it more efficiently) but it did what I needed in a very short amount of time. I find that I’m using Regex’s all the time lately and they’re really helping to automate a lot of very boring tasks.

Recent posts

It's been a long time coming.

0 Comments :: February 01, 2010

Array.prototype for fun and profit

1 Comments :: January 14, 2010

Ruby to the rescue

0 Comments :: December 04, 2009

Search the posts

Categories

Browse around

© 2010 Darren Newton, all rights reserved - Revision 322