Translate This WordPress Plugin

I have finally released my first public WordPress plugin. It’s fairly straightforward, but I wanted to go through a couple things I hadn’t done before, namely creating a project on Google Code and also submitting a plugin for the WordPress plugin hosting.

It’s basically an easy way to add the Google Translate Web Element to a page or a post on your website. You just wrap the content you want to translate with the a [translate_this] shortcode.

Here is the plugin on Google Code.

Categories: WordPress | Leave a comment

Early Morning At The Airport

I just arrived in Washington Dulles airport at 5:30 am, actually getting in almost 45 minutes early on a United flight! There is something wonderful about being at an airport early in the morning. So much so that it was making me feel almost poetic. It was still dark outside and there wasn’t very many people in the airport. Just a few people roaming around that were in a similar situation as me, connecting from an early arriving flight. The nice thing I guess was how quiet it is. No announcements yet, and hushed tones from passengers that were talking to each other.

As the sun came up, and the sky outside turned from black to the pre-dawn pink, I just felt an overwhelming since of joy. Perhaps a little because I am looking forward to being home with my family after two weeks abroad, but I sensed that it was something a little deeper than that.

Upon reflection, I think the reason why I love the airport so much, but perhaps why on this morning it filled me with a sense of joy, is, as the sun came up and slowly illuminated the aircraft parked at the gates, it struck me that the rows of airplanes awaiting passengers represent freedom. Hundreds of airplanes all waiting to take passengers wherever in the world they want to go. And it is at this time, that short window prior to the start of the hustle and bustle of the the day, that it feels as though you have limitless potential. The world is waiting. Pick your destination and go!

Categories: Aviation | Tags: , | Leave a comment

IE6 Transparent PNG Fix for Blackbaud NetCommunity

This was a tough one! Mostly because of having to work around the way Blackbaud’s CMS, NetCommunity works.

Since we still receive a surprisingly significant amount of traffic from people browsing with IE6, we had to make sure that our nice, slick semi-transparent PNGs were not showing up with the lovely gray-blue background that IE6 likes to put on there.

One nice thing about NetCommunity is it has jQuery built-in, and so I’ve been really trying to use it for all things Javascript, (which really isn’t a hardship since jQuery is so nice and easy to use – up until this point I had been using Prototype mostly).

So, cut to the chase, I was having a problem using Angus Turnbull’s great pngbehavior.htc solution, and searching around for a jQuery solution lead me to Supersleight. I uploaded it to a document library in our NetCommunity installation and then also uploaded a 1×1 transparent gif to the image library in NetCommunity.

Finding out the Document ID and the Image ID, I then added the following lines to each layout for our site:

  1. <script src="Document.Doc?id=192" type="text/javascript"></script>
  2. <script type="text/javascript">$('.tpng').supersleight({shim: 'view.image?id=1844'});</script>

Notice the shim… line points to the image id for the transparent gif. You could change the supersleight plugin, but this is easier and leaves the plugin intact.

But here is the most important part!
The plugin is looking for images with the class “tpng” and with a extension of .png. Since the images on NetCommunity are dynamically generated (i.e. view.image?id=1844) you have to drop down to the HTML in the editor and add &.png to the end of each image. For example:

  1. <img src="view.image?id=1844&amp;.png" class="tpng">

Of course, the HTML editor will convert the & to & amp;, but that is okay. Still works.

Yes, this is a rather crazy hack, but until that glorious day where IE6 is no longer used, it’ll have to do.

Categories: jQuery, NetCommunity | Leave a comment

Adding acts_as_reportable to environment.rb

We’re trying to make sure that our Rails app as a reproduce-able install process with required gems, and in doing so, adding the config.gem line into our environment.rb code.

For some reason, I kept getting a “gem does not exist – acts_as_reportable” error when I would then run rake gems:install.

I had the following line in my environment.rb

  1. config.gem 'acts_as_reportable'

But no luck.

Turns out to be an easy fix, if you’re really familiar with the syntax for environment.rb, which evidently I’m not. :)
Here is the proper line:

  1.   config.gem 'ruport'
  2.   config.gem 'acts_as_reportable', :lib => 'ruport'

Notice, that ruport is mentioned before it.

Categories: Ruby on Rails | Tags: | 2 Comments

Google Analytics Campaign URL Encoding with Ruby on Rails

So we’re launching a couple pages that we wanted to enrich the links and encode them with the Google Analytics campaign tracking data. (If you’re not familiar with it, you can take a look at the url builder here).

Basically, you create a campaign source (email, ad, or whatever) a medium and a name and it will build a url for you.

All of the links on the page we were building had the same source and campaign name, but different medium names.

So at the top of the page in the view (I thought about doing this in the controller, but for our purposes it is a per page kind of thing) I added a little erb code:

<% source_link = 'blah' medium_link1 = 'link1' medium_link2 = 'link2' campaign_link = 'nameofcampaign' %>
  1.  

Now, when you have a link_to helper in your page, add the following parameters after the :action

  1. :utm_source => source_link, :utm_medium => medium_link1, :utm_campaign => campaign_link

This way, if you want to update the URL encoding for Google Analytics for a different campaign down the line, it’s a matter of just changing the variables at the top of the page, rather than going down through the whole view to change every source and every campaign link.

Anyways, I felt proud of myself to be a little bit more DRY in my view with Google Analytics Campaign URL encoding.

Categories: Ruby on Rails | Tags: , , , | Leave a comment

Using before_save in the model

I was doing some refactoring of our email subscription functionality and I added a table column to include a hash of the email address which I would use in the unsubscribe process.

So I created a new migration that added the column and calculated the hashes for the existing email addresses in the table, however, it was not automatically creating the hashes using the current functionality.

So, it’s a pretty simple call in the model, a function called before_save.

My model file ends up looking like this, which creates the hash right before it saves the email address when someone subscribes.

before_save :add_email_hash

def add_email_hash
self.email_hash = Digest::SHA1.hexdigest(self.email + “addsometexttomakeithardtorecreate”)
end

And that’s it! An addition to the model file which is supposed to handle this sort of thing, rather than the controller.

Categories: Ruby on Rails | Leave a comment

Installed Quicksilver on my MacBook

I just re-installed Quicksilver on my MacBook.  I had installed it when I first got my MacBook in December of last year, but being a new Apple Fanboy, there was just too much new stuff going on in Leopard coming from Windows XP that I didn’t give it the chance it deserves.

Right now I’m using it in it’s most basic form, opening applications and switching between them using the keyboard.  I am looking forward to getting to the point of doing all those cool things you can do with it, but for now, I don’t want to overwhelm myself and end up not using it at all (which is what happened on try 1 when I got my MacBook).

If you’ve never heard of it, it basically allows you to hit a hotkey combination and then pick a file, application or something and do an action to it.  For example, to switch to Entourage, I type in Cmd-Space, then En (it looks up Entourage) and Enter, because the default action is “open.”

Anyways, it seems pretty slick and I look forward to learning the ins and outs of it.

If you’re interested in it, you can check out the website here: http://www.blacktree.com/

Categories: Mac Stuff | Tags: , , | Leave a comment

Check out my “Now Reading” Plug-in!

While on Africa, we stayed in hotels without telephones and TVs.  It was wonderful and I read 7 books in just 3 weeks.  It rekindled my love of reading, and I found this neat plug-in to showcase my current book I’m reading as well as the books I have read since July 1, 2008.

I think it’s pretty cool.  Hopefully you do to.

If you’re interested in the WordPress Plug-in, you can find it here: http://robm.me.uk/projects/plugins/wordpress/now-reading

Categories: General | Leave a comment

Load Sample Data into Dev Database

I needed to load the same type of data into my rails app and then mess around with it to see if my changes broke anything, and the reset the data easily to a standard data set.

Originally I was using the rake command:

  1. rake db:fixtures:load

which loads all of the fixtures you currently have in /test/fixtures.  This works okay, except the test fixtures that I have in that directory are specifically written for unit tests and don’t always have the all the fields filled out because I’m only testing certain things.

Basically what I was trying to do was create some fixtures somewhere else that would hold real data that I could populate to my website, try out new migrations and different things on the site and then be able to refresh back to the start after manipulating the database via my website.

I also tried making a data-only migration, which works, but I didn’t want to really do it that way, because the data is only for my dev environment.

So what I ended up doing was something similar to what I found here: http://quotedprintable.com/2007/11/16/seed-data-in-rails

I created a custom rake command under /lib/tasks (if there isn’t a file there already, create one called “database.rake”)

Then in the file add the following code:

  1. namespace :db do
  2. desc "Load sample data fixtures (from db/fixtures) into the development environment's database."
  3. task :sample => :environment do
  4. if RAILS_ENV == 'development'
  5. require 'active_record/fixtures'
  6. Dir.glob(RAILS_ROOT + '/db/fixtures/*.yml').each do |file|
  7. Fixtures.create_fixtures('db/fixtures', File.basename(file, '.*'))
  8. end
  9. else
  10. puts "You cannot run this from the production environment."
  11. end
  12. end
  13. end

The basic changes from the Quoted-Printable article that I made was to add the check for the development environment, as you wouldn’t want to accidentally run this from your production server and overwrite your database with your sample data.

Now create a directory in /db called fixtures add all your .yml files for each of your models into the /db/fixtures directory and every time you need to refresh your development database to your sample data, simply run the following rake command:

rake db:sample

Pretty cool, huh?

Categories: Ruby on Rails | Tags: , | Leave a comment