Archive for the ‘RubyIreland’ Category

Blackout Ireland Campaign Begins – No to Irish Internet Censorship

Thursday, March 5th, 2009

The battle for control of the Internet has begun within Ireland. In the red corner, Eircom has sided with the Big Four record companies – Sony-BMG, Universal and Warner and EMI – who are seeking to control the Irish Internet using coporate censorship and civil law techniques. In the blue corner, the Blackout Ireland campaign is looking to highlight the dangers of this censorship and has used social networking tools such as Twitter and Facebook to build support to protest this decision. A similar campaign was succesful in New Zealand, will it work again here?

Read more on OpenWriters.org.

Bug of the Day: nil.include error with create_time_zone_conversion_attribute

Thursday, January 22nd, 2009

This was an ‘orrible bug. Tired and midway through writing up a Ruby on Rails tutorial on setting up emailing with AR Mailer and a little postfix configuration I wasn’t exactly in the mood for a bizzarely cryptic issue to waste my time. Enter the mysterious create_time_zone_conversion_attribute? method in all it’s glory. Basically you will get this error if you set …

config.cache_classes = false

… wherever it is set in your environment files (in my case config/development.rb) but the error goes away if you change it to …

config.cache_classes = true

… bloody daft! Here is the bug on lighthouse. Arrgh!!!!

Anyway here is the full stack trace which may help someone googling to pick up this page

NoMethodError in UsersController#create

You have a nil object when you didn’t expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.include?

/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/attribute_methods.rb:142:in `create_time_zone_conversion_attribute?’
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/attribute_methods.rb:75:in `define_attribute_methods’
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/attribute_methods.rb:71:in `each’
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/attribute_methods.rb:71:in `define_attribute_methods’
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/attribute_methods.rb:350:in `respond_to?’
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:2587:in `attributes=’
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:2583:in `each’
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:2583:in `attributes=’
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:2283:in `initialize’
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:691:in `new’
/usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/base.rb:691:in `create’
vendor/gems/ar_mailer-1.3.1/lib/action_mailer/ar_mailer.rb:92:in `perform_delivery_activerecord’
vendor/gems/ar_mailer-1.3.1/lib/action_mailer/ar_mailer.rb:91:in `each’
vendor/gems/ar_mailer-1.3.1/lib/action_mailer/ar_mailer.rb:91:in `perform_delivery_activerecord’
/usr/lib/ruby/gems/1.8/gems/actionmailer-2.2.2/lib/action_mailer/base.rb:526:in `__send__’
/usr/lib/ruby/gems/1.8/gems/actionmailer-2.2.2/lib/action_mailer/base.rb:526:in `deliver!’
/usr/lib/ruby/gems/1.8/gems/actionmailer-2.2.2/lib/action_mailer/base.rb:392:in `method_missing’
app/controllers/users_controller.rb:47:in `create’
app/controllers/users_controller.rb:45:in `create’

Happy hackin’

Hackin on Gruff – A Brief Overview of Gem Development with Ruby

Friday, January 16th, 2009

Ah such is the life. Chillin’ in Havana (the bar, unfortunately not the city), hackin’ away on Gruff of all things. This is the my first attempt at development on a gem and it has to be said is surprisingly satisfying. Getting gems to build is a doddle. Here’s a great link that shows how it’s done in moments. Also a handy thing to know is how to suck the code out of your OS’s gems directory and unpack them to under your app’s vendor/gems directory – all courtesy of VendorEverything. You can create the vendor/gems directory manually if it doesn’t already exist.

When developing on the gem, I found that the best strategy was to clone down the gem source code from GitHub or Rubyforge to under the vendor/gems directory of my application rather than using the OS package unpacking technique of Vendor Everything (though they do it more for deployment than development – which is a great idea). That way I could easily stay on top of the latest source code using git. Actually, to make things even cleaner I downloaded the Gruff gem source code to a different directory totally unrelated to my sample project and then symlinked to it from under vendor/gems of my app. Clean as an (unused) whistle!

And with Gem, Git and GitHub behind me life was trouble free. Now back to my search for great Cuban cigars…

Did Vista contribute to Dell’s Limerick closure?

Monday, January 12th, 2009

Chris Mellor’s recent article on Channelregister.co.uk concerning Dell’s Limerick manufacturing exodus covered various reasons for Dell’s decision. Many of these break no new ground – it is simply the economics of the situation Dell finds itself in. But there were some subtleties that he unearthed that haven’t been stated by many commentators. Firstly, had there been sufficient demand for the notebooks that Dell were producing, then it would have taken both the Irish and Polish plants to satisfy that demand. The downturn clearly put a dramatic dent in the purchasing of notebooks but even before that Dell had been overtaken by HP as the world’s biggest supplier; and both Dell and HP were suffering at the hands of Apple. In June 2008, Jordan Golson reported in The Industry Standard that at Apple notebook sales were up 61% since Q1 ‘07. It seems that the Leopards and Tigers that populate Steve Jobs virtual zoo of operating systems were propelling Macbook sales to new heights while Vista was dragging Windows Notebook sales to down to Davy Jones locker.

Meanwhile a completely new category of computers arrived – Netbooks – small low cost devices, pioneered by Asus and their initial range of Linux-based machines. These began to cut into the low end of the laptop sales and proved to be a disruptive force in the market. After years where people were paying extra money for small form factor laptops, Asus came along and made the cost of small portables proportional to their size, in a game changing move that would haunt the mainstream laptop manufacturers as time wore on. Things got so bad for Vista’s adoption figures that Microsoft had to begin counting Windows XP sales as Vista sales via their controversial ‘downgrade licence’ program that allowed the likes of Dell to continue offering XP as an operating system on the machines they sold and allowed Microsoft to claim that another copy of Vista was now in circulation. But it wasn’t the kind of thing that marketing dreams are made of. Even in August of 2008 research suggested that more than one in three new PCs were still being downgraded to from Vista to XP.

So we set off into 2009 with more battles looming in the desktop, notebook, netbook and server markets. And who knows, maybe a completely new computing category will yet again be invented this year. Apple, Windows and Linux continue to vie for the position as the OS supreme. And with Internet Explorer’s market share falling to 68% from near dominance a few years ago,  gaps are still appearing in the browser market that will encourage Mozilla, Google and Apple to continue to innovate with Firefox, Chrome and Safari.

Windows 7 is somewhere on the horizon. It will come too late for Dell and its Limerick workers – will it come too late for Microsoft?

Uninstalling Gems from ~/.gem in your Home Directory

Saturday, January 10th, 2009

“It’s installed Gem but not as we know it”
– Bones, if he was a Ruby Developer –

Unfortunately, a careless keystroke can leave gems in lots of unusual places. About five minutes ago, that fate befell me as I ended up with gems under my home directory at ~/.gems. Not what I was expecting. To make matters worse when I tried to remove them I had no success – possibly there were PATH or GEM_PATH issues

Fortunately, Google was to the rescue before you could say ‘gem is no apt-get’, with the command…

gem uninstall ruby-debug-ide --install-dir $HOME/.gem/ruby/1.8

… where in this case ruby-debug-ide is the misplaced gem in question.

Thanks to this thread for the solution.

Better to be Oriented than an Object

Wednesday, December 10th, 2008

Bit of a mixed bag of thoughts going into this post. Originally it was motivated by a couple of interesting points that I came across a bunch of ideas on programming by Kristian Dupont but then it turned into one of those link hopping sessions where you end up click through a wealth of interesting material.

A Tip or Two for your Troubles

Kristian outlined a good test to determine if adding a comment to your code is justified saying that “they should contain the word ‘because’. This way, you know that you are answering a why rather than a what.” That’s a great test I think. If your comment fails the test then you may well be more in need of a refactor than a comment.

Secondly, when thinking about the classes you plan to use in your code, especially domain models, bear in mind that you’re not actually trying to model the real world in a physical sense. For example, if you’re writing software for a car dealership and one of your classes is going to be a car remember “You’re not implementing a car. You’re probably implementing a record of a car which can carry a number of stock items from one city to another, with a certain mileage and speed.” The key thing is the context of what you’re trying to implement and focus on that – often the real world will map nicely to your domain model but don’t force things where doesn’t. To shoehorn irrelevant aspects of the physical world into your models doesn’t make it “more object oriented” or more correct – quite the reverse. Generally, this in not a problem with the attributes for your models, rather it is a problem with relationships and in particular with inheritance. Should a subclass really be a subclass – just because it is in the real world doesn’t necessarily mean that your software be designed on the foundation that it is. This brings on nicely onto the other article, The Rise & Fall of Object Orientation, which ended up being another inspiration for this post.

What is Object Oriented these days anyway?

Danny Kalev argues that traditional OO is something that is less and less likely to be found in areas such as STL library of C++, as techniques such as inheritance give way to more template driven styles of programming. The problem he states “is that a member function is useful only for a single class” and goes on to highlight how this doesn’t work well for things such as a library of containers.

“If each container class defines its own size() member function, you will end up writing numerous size() functions that basically do the same thing.”

Better to use a standalone function to solve the problem which can be used across the board by any class irrespective of inheritance hierarchies. It isn’t just C++ that has looked to functional programming techniques to solve problems that traditional OO couldn’t deliver on. Languages such as Ruby have effectively made blocks and closures one of the core and most used features of the language. All iteration is done through blocks and lamba functions can solve tricky problems in an elegant manner.

It seems that traditional OO struggles most with collections but works well enough for single objects. Neal Ford thinks that Object Oriented Development is the wrong way to even frame the question of code reuse. Instead the focus should be on Library Oriented Development. “Ultimately, the class is just too fine grained to really achieve reuse, but libraries can.” On Java he states that while it “is a library oriented language, no good facilities exist within the language to manage libraries” and notes it sorely lacks a fixed directory structure such as in Ruby on Rails, where plugin developers know the layout of the projects they will be interfacing with from the get go.

Whether you prefer to consider your approach to software development an Object or Library Oriented approach it does seem that the modern developer will be drawing on a wide range of programming paradigms that go beyond traditional OO philosophy. In a hotly debated and opinionated field, it appears that the one true killer approach has not yet emerged to truly simplify and streamline development. At least it will continue to provide software developers, designers and architects with plenty to debate during their coffee breaks for years to come!

3 Cheers for OSS Barcamp Dublin!

Sunday, November 23rd, 2008

Another exciting event has just been announced for Dublin next year with an Open Source Software Barcamp planned for Dublin March 28th next year. And you could be one of the speakers! The idea behind a barcamp is to have a casual relaxed atmosphere where the attendees can help drive the schedule – like a conference done in the spirit of Digg. For more info check out Laura Czajkowski’s blog post and if you want to keep up to date with further details you can track things on ossbarcamp on twitter.

Troubleshooting fcgi and the dreaded undefined method `require_gem’ error

Thursday, October 9th, 2008

It happens to the best of us. We’ve coded our app go to deploy it and encounter some dispatch.fcgi issue. Today was the turn of
<br />
dispatch.fcgi error: undefined method `require_gem' for main:Object (NoMethodError)<br />

Well way to troubleshoot and arrive at a solution is to actually run ./dispatch.fcgi. I didn’t know you could do this! It’s well handy! If you are on a remote server to which you don’t have ssh access then you can probably still run it as a cron job. Something like cd /path/to/my/app/public && ./dispatch.fcgi should do it. Remember that the dispatch.fcgi file is in the public directory of your application. The combination of running ./dispatch.fcgi and viewing the Rails log file revealed the useful error message above. Then a quick google search revealed that we need to change require_gem to simply gem (see here).

I had to change this in the dispatch.fcgi and then grepped the whole application directory for any instances of require_gem and changed them to gem too.

Getting Ruby Plasmoids up and running in KDE 4.1 (on Kubuntu)

Saturday, August 2nd, 2008

NOTE: THIS ARTICLE IS NOT YET COMPLETE. IF YOU FOLLOW IT THEN YOU WILL GO A LONG WAY BUT THE PLASMOID IS NOT YET DISPLAYING. SEE THE ‘Run your applet’ SECTION NEAR THE END OF THIS ARTICLE BEFORE PROCEEDING.

Introduction
KDE 4.1 is an absolutely terrific release of the KDE desktop, licking most of the issues presented in the original 4.0 release. Although it is still an early adopter release, 4.1 will be of interest to techie’s who want to get their mitts on a sexy new graphical interface and is reasonably stable for daily usage. Not quite ready for Aunt Tillie yet though! One of the nicest features is the beauty and simplicity of Plasmoids and these super flexible little gadgets can now be written in Ruby – well almost!

This guide assumes that you’re using Kubuntu Hardy Heron. But you should be able to adjust the instructions for any distro.

  • The starting point for our tour is to have Ruby installed. Google this if you’re unsure as to whether or not it’s installed.
  • We need to install cmake via ’sudo aptitude install cmake’. This is a cross-platform build system, similar to make.
  • It’s likely that you will need to install the build UNIX build tools via ‘aptitude search build-essential’.

Get coding!
And now you’re be ready to go. The main tutorial out there on Ruby Plasmoids at time of writing is the Ruby Applet tutorial on KDE Techbase. This is a very good, well written guide on creating a simple Ruby applet in which a web browser is embeded inside the plasmoid. But the guide has a couple of gotcha’s, especially for the newbie (myself included!), so we have listed solutions to these problems as we go. In summary, use our article as an supplement to KDE Techbase’s.

Ok, to start with a demo everyone wants a nicely packaged directory of files, so let’s quickly put together the basic directory structure for our plasmoid – it’s pretty simple!

  • Create a directory called ‘ruby-web-applet’
  • Save the files plasma-ruby-applet-web.desktop and web_applet.rb into this directory.
  • Create a file called CMakeLists.txt under your ruby-web-applet directory and paste the following code into it
set(SERVICES_INSTALL_DIR /usr/lib/kde4/share/kde4/services/)
set(DATA_INSTALL_DIR /usr/lib/kde4/share/kde4/apps/)

FIND_PACKAGE (Ruby REQUIRED)

include_directories( ${RUBY_INCLUDE_PATH} )
install(FILES plasma-ruby-applet-web.desktop DESTINATION ${SERVICES_INSTALL_DIR})
install(FILES web_applet.rb DESTINATION ${DATA_INSTALL_DIR}/plasma_ruby_web_applet)

Go to KDE Techbase
Once you have the above directory in place, go and read the Ruby Applet tutorial on KDE Techbase article down to just before the ‘Install and test the Applet’ paragraph. This will teach you what’s going on in the code. At that point come back to me as I’ll go into a little more detail on the final installation procedure!

You’re back!
Great! Ok, so we have the files on disk, you have a good idea of what the code is doing, now let’s install it and kick your plasmoid into action!

Open the CMakeLists.txt file listed above in a text editor. Change the path listed for KDE4 services and data directories to the ones on your system. These are the lines to change.

set(SERVICES_INSTALL_DIR /usr/lib/kde4/share/kde4/services/)
set(DATA_INSTALL_DIR /usr/lib/kde4/share/kde4/apps/)

Do this by replacing ‘/usr/lib/kde4/share/kde4/services/’ with the output of the command ‘kde4-config –install services’ and replace ‘/usr/lib/kde4/share/kde4/apps/’ with the output of the command ‘kde4-config –install data’ command. If you are using Kubuntu then they should be the same as mine but otherwise you may need to change them.

Then make sure you are inside your ruby-web-applet directory and type

cmake .

to generate nice makefiles for you which the make command can then use. Don’t forget the trailing dot! Now type ‘make’ and ’sudo make install’. This will install your plasmoid code into the KDE4 services directory (you can see where this is by running ‘kde4-config –install services’) and your plasmoid data into the KDE4 data directory (you can see where this is by running ‘kde4-config –install data’). Effectively, the installation just involves the two files – plasma-ruby-applet-web.desktop web_applet.rb. If it’s worked then you’ll get output like

Install the project…
– Install configuration: “”
– Installing: /usr/lib/kde4/share/kde4/services/plasma-ruby-applet-web.desktop
– Installing: /usr/lib/kde4/share/kde4/apps/plasma_ruby_web_applet/web_applet.rb

The applet is now installed!

Run your applet (THIS DOES NOT WORK YET)
There are two ways to do this. In a developer kind of way you can run ‘kbuildsycoca4′ from the command line followed by ‘plasmoidviewer plasma-ruby-web-applet’. Unfortunately this currently brings up the error

findServiceByDesktopPath:  not found
findServiceByDesktopPath:  not found

IF YOU HAVE A SOLUTION TO THIS THEN PLEASE COMMENT BELOW!!!

As a user, the cmake/make/make install procedure should have done all the necessary to install your plasmoid and you can activate it by going to the right of the task bar and clicking the Add Widgets icon. You should see your plasmoid listed but unfortunately this is not yet working – presumably for the same reason as the above. Oh well, I’m sure a solution will soon be posted. Until then, happy hackin!

Final notes

Note that the KDE techbase article provides a version of this file but it didn’t work for me because

  • I knew nothing about cmake or cmake files and I didn’t even cop that right clicking on the CMakeLists.txt file link in their article and saving it to disk would also save a load of HTML into the file
  • The line ‘FIND_PACKAGE (RUBY REQUIRED)’ should really be ‘FIND_PACKAGE (Ruby REQUIRED)’ as it’s case sensitive and will otherwise give you the error

    CMake Error at CMakeLists.txt:6 (FIND_PACKAGE):
    find_package could not find module FindRUBY.cmake or a configuration file for package RUBY.

    Adjust CMAKE_MODULE_PATH to find FindRUBY.cmake or set RUBY_DIR to the directory containing a CMake configuration file for RUBY. The file will have one of the following names:

    RUBYConfig.cmake
    ruby-config.cmake

  • The destination targets specified in the file didn’t work for me. Perhaps some environment variables need to be set somewhere
  • I didn’t even know how to use cmake! Or that you needed to follow it up with ‘make’. Anyway we’ll come cover this soon!

I didn’t need to set any CMAKE_MODULE_PATH but if you are having troubles with this then it’s at /usr/share/cmake-2.6/Modules/ on Kubuntu Hardy Heron. You may be able to set it in your script if your having difficulties as follows ’set(CMAKE_MODULE_PATH /usr/share/cmake-2.6/Modules/)’. Again I haven’t tried this my self!

A Little Help on Importing Gmail Contacts using Ruby on Rails

Wednesday, June 25th, 2008

We came across a fabulous article on getting your RoR app to pull contacts from your Gmail account at Atlantic Domain Solutions: Import Gmail Contacts using Ruby on Rails. Kudos to Atlantic Domain Solutions! This is a really great article. The only slight issue is that it omitted a couple of details which may confuse the newbie – in particular, where does all the code in points 1, 2 and 3 go and how do the code snippets relate to each other.

So here’s a set of clarifications to the original article (a ‘meta-guide’ if you will), as we didn’t want to just rip off these nice folks source code. Thus read these clarifications in conjunction with the original Atlantic Domain Solutions guide.

We’ll assume that you know how to create a new rails app from scratch and create a controller. While you’re following this you can use localhost as your server (eg. the default localhost:3000).

Create yourself a controller called ImportedContacts

class ImportedContactsController < ApplicationController

    def authenticate
        # Put the code from point 1 in the Atlantic Domain Solutions article here.

        # Note:
        # Set the next_param to the follow on controller action. For example,
        # next_param = url_for(:action => 'authorise')
    end

    def authorise
        # Put the code from point 2 in the article here.

        # Note:
        # I changed some of the code as shown below...
        # if resp.code == "200"
        #     token = ''
        #     data.split.each do |str|
        #         if not (str =~ /Token=/).nil?
        #             token = str.gsub(/Token=/, '')
        #         end
        #     end
        #     redirect_to(:action => 'import', :token => token)
        # else
        #     redirect_to ('/')
        # end
    end

    def import
        # Put the code point 3 from the article here.

        # Some notes:
        # Put the line 'authsub_token = params[:token]' at around line 4 of this method
        # (just after the two requires). It was accidentally omitted in the original article.
        # I also changed the local variable 'contacts' to '@contacts' so that it is available to views
    end
end

To see the contacts after importing, I created a folder called ‘imported_contacts’ under app/views and placed the file import.rhtml in it, containing the following code.

<table>
  <%= @contacts.map { |c| "<tr><td>Name: #{c['name']}</td><td>Email: #{c['email']}</td></tr>" } %>
</table>

Ok! You should be ready to rock! Ensure that you are not logged into gmail and visit http://localhost:3000/imported_contacts/authenticate

You should be brought to a Google account login page. Login and you will be brought to the Google page for allowing third party access to the Google API. Click ‘Grant’ and you should be brought to your app’s import.rhtml page which should hopefully be displaying all your lovely contacts! Hurrah!

Blogged with the Flock Browser