Troubleshooting fcgi and the dreaded undefined method `require_gem’ error

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

dispatch.fcgi error: undefined method `require_gem' for main:Object (NoMethodError)

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.

Recording Sound in Kubuntu 8.10 (running KDE 4.1)

September 14th, 2008

Exciting times ahoy! This weeks mystery was to get sound recording with the minimum of fuss. We’re not sure what soundcard is running inside the Dell Inspiron 1520 which was our test laptop but it seems to report itself as an HDA Intel SigmaTel STAC9205 in the system settings. Anyway, the first thing to do was to apt install audacity which can then be used for testing the recording functionality. Not being sure if the laptops builtin in mic had been detected correctly, we jacked in an external microphone into the mic socket.

This didn’t produce any encouraging results initially when we tried recording in audacity so we opened up the KDE volume controls by clicking the speaker icon on the taskbar and electing to open the mixer. Unfortunately the GUI controls for the mixer doesn’t have the full complement of volume controls so it was the good ol command line to the rescue - typing alsamixer in terminal brings up a nice range of controls. You can navigate between screens of controls with the tab key and jump from control to control using the left/right arrow keys. The trick was to navigate to the two controls marked ‘Capture’ and bump up the volume (they also need to be activated by pressing the spacebar when you’re on the control). Additionally, there were two controls marked ‘Digital’. One of these controlled the volume of the mic (via the up and down arrows) and the other switched between analog and digital mode (again via the up and down arrows). We found that the latter had to be set to ‘Analog I’ for the best result.

Then it was back to audacity to record a bit of chatter - and then lament how weird ones voice sounds when recorded! Now get mixing mon amis!

QUICK UPDATE (14 Sep 08)
One issue that occurred was that after recording a sample, it couldn’t be played back(”Error while opening sound device. Please check the output device settings and the project sample rate.”). Additionally, a second track couldn’t be recorded. The solution to these problems was to open the Preferences dialog and set both the Playback and Record devices to ALSA (default). Reference: http://audacityteam.org/forum/viewtopic.php?f=18&t=3377

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

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

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

Just Diff the Internet

June 22nd, 2008

Woke up this morning and found myself dead… Well, more to the point, my Internet connection dead. So being a Nymphobyte - someone feverously attracted to a reliable high bandwidth connection - there was little else to do than ponder the state of broadband in Ireland. Options are limited in the land currently home to the so called ‘Pariahs’ of Europe. Just make our broadband better and we’ll vote Yes! to Lisbon II and even Lisbon III ‘The Search for Spock’. Until then, you’re better off sending your packets of data back and forth via carrier pigeon rather than trying to connect via the empty promises of the current providers.

At least things aren’t as bad as in Sweden, oft thought of as land of the liberal and freedom loving Swedes, where their elected leaders are trying to sell them down the river - forcing a copy of all networked communications to be forwarded on the government so that they can, presumably, check for things like terrorists trying to share the latest episode of Desperate Housewives over Bittorrent. Sweden is now being mentioned in the same breath as China and Saudi Arabia with respect to Internet Freedom. According to an Information Age article even Google, not known to be adverse to collecting data on people, has been heavily critical of the crippling legislation. Blogger Oscar Swartz has a rallying mayday call on his site. Yes, that’s right, even the Scandinavians have given up on civil rights - now we know the world is doomed! They’re kind of like a civil liberties version of those budgies that used to warn of noxious fumes down the mine shafts in the old days - once they go tits up then you know the game is over.

Nope, freedom is not on the menu anywhere this week. An article in The Economist took stock of the scale of civil liberties that have been eroded under the Labour government and the relative apathy that this has been met with by the people. Gordon Brown, despite the having the popularity of Brian Cowan at a Eurocrat orgy, has even managed to push through legislation in Parliament to the effect that one can now be detained for 45 days at a go without charge. That’s over 6 weeks! You could miss the whole European championships if you’re unlucky enough! Which might suit you if you’re a Portuguese or Croatian fan, after their sides painful exists. But 6 weeks! Perhaps Gordon just has a secret repressed side that he didn’t know about - which is subconsciously upset that Ireland is now seen as more Eurosceptic than Britain. Forty five days isn’t so bad though. After all, Tony Blair wanted to lock ‘em up for 90 days without charge. Why not go the whole hog and just lock people up at birth? It saves all that awkward decision making and you wouldn’t even need National Identity Cards anymore. Mind you, who needs ID cards when everyone one has already gotten their own copy of secret government dossiers that they picked up on the Tube on the way to work. Now there’s a government I wouldn’t trust mind my dog for the weekend, never mind my confidential information. And I don’t even own a dog…

It’s been a tough week all right. It’s hard to know how to stay on top of things. My great plan is to do away with RSS feeds and subscriptions and just diff the Internet each morning before going to work. If there was some interesting news found it could be managed using git and deltas emailed to friends to keep them informed. Sure, it would be a lot of data to contend with, but there would be some scant satisfaction knowing that it would make those draconian Swedish government servers that spy on their citizens work that little bit harder!

Quick Example of Serialisation via to_json in Ruby On Rails

May 19th, 2008

Ruby On Rails provides a few neat ways to serialise/deserialise objects to JSON. Out of the box you get the following approaches

SERIALISING

* json_string = a_house.to_json

DESERIALISING

* an_object = ActiveSupport::JSON.decode(json_string) # gives you an object of type Object
* a_house.from_json(json_string) # gives you an object of type House, note that a_house
                                             # is an instance of House

These are pretty straightforward and do exactly what they say on the tin. Of the deserialising methods, note that using ActiveSupport directly gives you an object of type Object so you may prefer the stronger typing of the second technique which gives you an actual House object.

Note: There’s been some great improvements to JSON support built right into Rails since Rails 2 has come around. For more info on this see here.

When things just aren’t enough…
There are times when you will want to override the default serialisation that Rails provides - such as if you want to do some object ‘flattening’ like including an attribute from an association on serialising. Now before proceeding check out the latest Rails 2 JSON support mentioned at the end of the previous section as this might make your life a lot easier. Otherwise, let’s press on with an example of DIY JSON handling.

Given a House object which has an associated Owner object, you might want to include the Owner’s name attribute when serialising a House.

House Class
- has address and value attributes
- has an associated Owner object

Owner Class
- has a name attribute

We’ll need to override the default to_json method on the House model.

class House::Base
  def to_json
    result = Hash.new

    self.class.content_columns.each do |column|
      if self.attributes.include?(column.name)
        result[column.name.to_sym] = self.send(column.name)
      end
    end

    if self.attributes.include?(column.name)
      result[:owner_name] = owner.name
    end

    result.to_json
  end
end

The above was partially taken from the howtogeneratejson page on the Rails wiki, which is has little bit more detail. Now all you need to do is call the a_house.to_json method and you get lots of lovely JSON which represents your model! One final note is that you may not want to override the default to_json method. If not, just call your method something else like to_custom_json. Also, there’s

Mercurial, Python and a Packet of Crisps

April 7th, 2008

Came across this exciting bit of news on the ol wireless just recently that rails is moving from SVN to Git. Exciting times indeed as more and more developers are realising the merits of distributed source control to manage an ever expanding code base. TIP’s been in the fortunate position of working a lot with Mercurial, an alternative to Git, for the last few weeks and these types of tools are just a great way to work.

One of the big pluses is that your code and your repository (the history of all edits you’ve ever made to the code) is all in one directory which makes the process of source control really filesystem based. This is great when you’re learning and just experimenting as you become more familiar with your new favourite toy. If you want to try something out, you just copy the directory somewhere and if it all goes to pot then it’s just a quick copy command to restore it back to its original state!

If you’re a Ruby or Python dev one of the really nice things about Mercurial (also known as hg - after the chemical symbol) is that it’s done in Python, which means that it’s pretty easy to hack a bit of code together if you want to extend functionality. A whole Saturday was lost to the cause of hacking Mercurial in Dublin’s Central Hotel last weekend - as your host recovered from a bout of Extreme Coughing (there are more germs going round here at the moment than sheep in New Zealand!) over a pint of orange and a packet of crisps. Good fun! It was kind of weird though. As soon as urs truly had booted up the laptop, a bunch of folks grabbed seats to the back of the room muttering about Ubuntu cds and wifi. Sounds like Linux is all over Dublin like a rash. A very nice rash of course!

Getting the Huawei E870 to work on Kubuntu (and Mobile Internet from O2)

March 26th, 2008

It’s a shiny express card and it promises Internet free from cables, plugs and sockets but will it work on your pretty Kubuntu laptop? Let’s hope so. This guide worked for me and hopefully it’ll work for you too!

Now before we start let me tell you my setup. I’ve got this working on a Kubuntu based Dell Inspiron using O2 as my network provider. It did not work on a separate Dell Vostro running Ubuntu 7.10 (however I did get it working on a different Kubuntu 7.10 Dell Inspiron laptop). So I’m not sure whether that was a Ubuntu or Vostro thing or just bad luck. Also, note that the below approach worked for me when setting up Huawei’s E220 USB modem too.

In any case, here’s the 6 step plan to happiness
1.) Download the huaweiAktBbo-i386.out file
2.) Create the /etc/chatscripts/huawei-e220.chat file
3.) Create the /etc/ppp/peers/huawei-e220 file
4.) Create the /etc/wvdial-huawei.conf
5.) Edit the /etc/resolv.conf
6.) Create and tailor the /home/username/bin/connectme script (and chmod it!)
7.) Tip of the day - lose the Edge!

1.) Download the huaweiAktBbo-i386.out
This can be done by visiting http://www.kanoistika.sk/bobovsky/archiv/umts/ and downloading the file huaweiAktBbo-i386. If you really want you can also build it from the C source provided (in order to build it you will need to have a C compiler and some basic tools on your system). NB: Copy the huaweiAktBbo-i386.out file to your /home/username/bin directory after downloading. If you don’t have a bin folder under your home directory then create one (’mkdir /home/username/bin’). Also ensure that it is in your $PATH environment variable. Try echo $PATH and if you don’t see it listed add the following line to your /home/username/.bashrc file

export PATH=$PATH:/home/username/bin

To get this change immediately picked up by your shell run the command ’source ~/.bashrc’. This something I didn’t learn for years!!! D’oh!

2.) Create the following /etc/chatscripts/huawei-e220.chat file

TIMEOUT 3
ABORT BUSY
ABORT 'NO CARRIER'
ABORT VOICE
ABORT 'NO DIALTONE'
ABORT 'NO DIAL TONE'
ABORT 'NO ANSWER'
ABORT DELAYED
"" ATZ
OK ATQ0V1E1S0=0&C1&D2
OK ATDT*99#
CONNECT ""

3.) Create the /etc/ppp/peers/huawei-e220 file

/dev/ttyUSB0
460800
noipdefault
defaultroute
persist
noauth
nodetach
usepeerdns
connect "/usr/sbin/chat -vf /etc/chatscripts/huawei-e220.chat"

4.) Create the /etc/wvdial-huawei.conf

[Dialer Defaults]
Modem = /dev/ttyUSB0
#Baud = 3600000
Baud = 7200000
Init1 = ATZ
Init2 = ATQ0 V1 E1 S0=0 &C1 &D2
Init3 =
Area Code =
Phone = *99#
Username = ppp
Password = ppp
Ask Password = 0
Dial Command = ATDT
Stupid Mode = 1
Compuserve = 0
Force Address =
Idle Seconds = 0
DialMessage1 =
DialMessage2 =
ISDN = 0
Auto DNS = 1

5.) Edit the /etc/resolv.conf file
Add the following entries at the top of this file (they are O2’s nameservers)

nameserver 62.40.32.33
nameserver 62.40.32.34

6.) Create the and tailor the /home/username/bin/connectme script as follows (and chmod it!)
Note: See step 1 for more instructions if you don’t have a bin folder in your home directory

#!/bin/bash
sudo /home/username/bin/huaweiAktBbo-i386.out # CHANGE THIS TO YOUR 'USERNAME'
sleep 3 # wait for the USB host to settle down...
sudo wvdial --config /etc/wvdial-huawei.conf
#/usr/sbin/pppd call provider

Then just do a ‘chmod u+x /home/username/bin/connectme’ from the command line (to allow you to run ‘connectme’ from the command line directly) and hopefully you should be ready to rock! The next step is to insert your E870 into the express slot. You might start to see Linux picking up the the devices and popping dialogs asking you if you want to mount the device (you should select ‘Cancel’ for them all).Wait about 5 seconds for it to steady itself and then run ‘connectme’ from the command line. You should see

Hladam HUAWEI E220 a prepnem na modem - bbo 06
4 set feature request returned 0
Prepnute-OK, Mas ttyUSB0 ttyUSB1 (cez usbserial vendor=0x12d1 product=0x1003)
pozri /proc/bus/usb/devices
WvDial<*1>: WvDial: Internet dialer version 1.56
WvModem<*1>: Cannot get information for serial port.
WvDial<*1>: Initializing modem.
WvDial<*1>: Sending: ATZ
WvDial Modem<*1>: ATZ
WvDial Modem<*1>: OK
WvDial<*1>: Sending: ATQ0 V1 E1 S0=0 &C1 &D2
WvDial Modem<*1>: ATQ0 V1 E1 S0=0 &C1 &D2
WvDial Modem<*1>: OK
WvDial<*1>: Modem initialized.
WvDial<*1>: Sending: ATDT*99#
WvDial<*1>: Waiting for carrier.
WvDial Modem<*1>: ATDT*99#
WvDial Modem<*1>: CONNECT
WvDial<*1>: Carrier detected.  Starting PPP immediately.
WvDial: Starting pppd at Tue Mar 25 21:22:08 2008
WvDial: Pid of pppd: 11465
WvDial<*1>: pppd: H���h�[06][08]`�[06][08]
WvDial<*1>: Using interface ppp0
WvDial<*1>: pppd: H���h�[06][08]`�[06][08]
WvDial<*1>: pppd: H���h�[06][08]`�[06][08]
WvDial<*1>: pppd: H���h�[06][08]`�[06][08]
WvDial<*1>: pppd: H���h�[06][08]`�[06][08]
WvDial<*1>: pppd: H���h�[06][08]`�[06][08]
WvDial<*1>: pppd: H���h�[06][08]`�[06][08]
WvDial<*1>: local  IP address 62.40.58.185
WvDial<*1>: pppd: H���h�[06][08]`�[06][08]
WvDial<*1>: remote IP address 10.64.64.64
WvDial<*1>: pppd: H���h�[06][08]`�[06][08]
WvDial<*1>: primary   DNS address 62.40.32.33
WvDial<*1>: pppd: H���h�[06][08]`�[06][08]
WvDial<*1>: secondary DNS address 62.40.32.34
WvDial<*1>: pppd: H���h�[06][08]`�[06][08]

If you want to disconnect from the web simply press Ctrl-C twice to kill it off. The first time you press it, it talks of wanting to exit gracefully - but better to press it a second time and exit effectively ;-)

You’ll see the following

Caught signal 2:  Attempting to exit gracefully...
WvDial<*1>: Terminating on signal 15
WvDial<*1>: pppd: H���h�[06][08]`�[06][08]
WvDial<*1>: Connect time 8.6 minutes.
WvDial<*1>: pppd: H���h�[06][08]`�[06][08]
WvDial<*1>: pppd: H���h�[06][08]`�[06][08]
WvDial<*1>: pppd: H���h�[06][08]`�[06][08]
WvDial<*1>: Disconnecting at Tue Mar 25 21:30:45 2008

7.) Tip of the day - lose the Edge!
Disclaimer: this is just my opinion as to the performance of the Edge network so O2 lawyers keep your knickers on (however Apple iPhone suckers, enjoy the sheer speed of the Edge network, getting dripfeed broadband at 1500 Euros a year!). In stark contrast though, my experience with the HSDPA network have been good. Yes, as you may have already guessed, the Edge network was not really delivering for me. But a friend of mine showed me how to change your O2 broadband Express card (or USB modem) settings so that it not even bother connecting if it can’t get a proper UTMS or HSDPA signal. For this you need a Windows friend. Install the express card on their machine and from the O2 broadband application and select “Tools->Choose Network Type->3G Only”. This setting directly updates the card so even when you switch back to a using it on a Linux box it will go with 3G only. If I don’t do this I’ve found that it will flip flop between Edge (GPRS) and 3G networks and drive you mad in the process. I found it pretty much impossible to even check my email on Edge.

Special thanks to Andy and Paul on the ILUG mailing lists for their help and also to O2, Vodaphone, Three et al. for providing Mobile Internet via hardware that can actually be used on an Open Source platform such as Linux; as we hopefully move from an era of proprietary lock-in and DRM-based crippleware to software that delivers genuine value for businesses and users. Vodafone have gone as far as having their own Open Source website to help along development at Betavine. Enjoy!

The revolution will not be televised! It will be streamed over TCP/IP…

Simple ‘Through Associations’ in Ruby on Rails

January 14th, 2008

This little article shows one way to model many-to-many relationships using a join table.

Obviously, The Penguin isn’t the first so here is an alternative good practical example which might give your good self an different perspective. Also this documentation has some more detailed information but doesn’t have a simple self contained example like below (and neglects to mention belongs_to in its primary example - at time of writing this).

Here goes. The following statements define our basic requirements.

* An order has many items
* An item has many orders
* We shall model this through a join table called order_items

orders     order_items    items
-----      ----------     ----
id         order_id        id
           item_id

Before we continue, please note that a massive massive thing to remember is that Order needs to have a has_many to the join table model AS WELL as a has_many (through the join table model) to Item. Also the join table model has a belongs_to for each model.

class Order < ActiveRecord::Base
has_many :order_lines #Don’t forget this line!
has_many :items, :through => :order_lines
end

class Item < ActiveRecord::Base
has_many :order_lines #Don’t forget this line!
has_many :orders, :through => :order_lines
end

class OrderLine < ActiveRecord::Base
belongs_to :order
belongs_to :item
end

Ok so that’s it folks! The Penguin has to admit that the above code hasn’t been run in a RoR interpreter so if has typo’s or smelly code please comment below.

One last thing is that if you’re going to try and present a RoR solution in an enterprise situation it is quite likely that the powers that be will want to see foreign key relationships in your database tables (note, this applies to all db relationships; not just man-to-many). These will give referential integrity to your associations. One very very handy and straightforward way to do this is using Red Hill’s foreign_key_migrations plugin. This really is great (it does pretty much all the hard work for you!) so it’s worth a serious look.

One gotcha with using foreign keys in Rails, is that the order in which test fixtures load becomes important. See Per Olesen’s post for tips on countering this. Other than that happy hacking and may the Rails Rise to Meet You!

EU Commission unDRMines European Multimedia Sector

January 5th, 2008

The ever confusing term ‘Intellectual Property’ gets another run out today as the EU attempts to shoot itself in the foot, yet again on crucial IT issues. This time the European Union wants to embark on a plan to encumber its multimedia sector in a cocoon of red tape through the introduction of DRM. And goes to the absurd length of stating that it is doing so in the interests of consumers. What the …???

The Irish Penguin is a die-hard market fanatic. The reason is not just because it’s the most efficient way to run an economy but rather that it is the best for the consumer (Note: The Penguin doesn’t think that its the best way to run some things like health care but that’s another story altogether). The bottom line is the customer truly is always right. Remember this for later. Which is way todays announcement is not just bad news for budding business entrepreneurs within Europe’s software economy but also a smack in the chops for European consumers. One of the frantic undertones of the EU is often one of desperation - an attempt to try and emulate America - in order to somehow shed the image of a union which is hamstrung fragmented markets and business unfriendly polices. Unfortunately, it sometimes goes about it the wrong way. Instead of the Japanese tradition of copying a process and improving it, the EU cumbersomely ambles towards the wrong target and periodically releases sound bites which it thinks will make it sound economically competent. Today was a comical case in point. Here is an excerpt from its press release.

“The European Commission has decided today to give a new boost to Europe’s online content sector. EU citizens should be able to enjoy easier and faster access to a rich variety of music, TV programmes, films or games via the Internet, mobile phones or other devices.”

Let’s read that first line again. The European Commission has decided what? This opening sentence sounds like the EU is trying to convince itself that this is a good idea. In reality, the European Commission has NOT decided today to give a boost to Europe’s online content sector. This is because included in its announcement the EU has decided that DRM (a completely misnamed and dangerous Digital Rights Management technology) should be forced on the European customer at every turn - in order to stifle the promising multimedia sector. It is highly useful to see that DRM has roundly been rejected by media consumers right across the globe. All of the major record company’s used to have DRM woven into their CDs and products at the turn of the year. DRM prevented users playing music on more than one music playback device. For example, it locked customers who had purchased an album online into playing it back on an iPod only; the user could not choose to play that same album on their home computer. And it also locked users who had bought CDs from playing them on their iPod. As sales plumetted and customers rebelled, EMI was the first to reject this notion and give back consumers the right to play their music on any device. That the left the remaining labels with an inferior product and they all quickly followed suit. Sony BMG, Warner Music Group and Vivendi’s Universal Music Group all now sell ‘clean’ products in United States which are not contaminated with DRM. This shows the power of the Free Market to correct problems like DRM. So if it makes sense for these major players to roundly reject DRM then how on earth can it make sense for the EU to move towards it? The answer - it doesn’t!

Ironically, the second sentence is also meaningless rhetoric. The EU Commission’s announcement today does NOT make it easier or faster to access rich multimedia. The only thing that can do that is solid broadband policies and Net Neutrality. Net Neutrality is crucial. It guarantees that the all services provided over the Internet are treated equal. This allows the separation of the bandwidth providers (such as European telecom companies and ISPs) from the content providers (movie distributors, news channels, websites, email services) in order to prevent the bundling of content with services. The big word there is ‘bundling’. If your telecom company is providing your movies via cable TV and an online company seeks to compete with them by providing movie downloads it is unwise to let the telecom company to control the bandwidth available to the online company - clearly it would be in the Telecom’s interest to restrict bandwidth for movies thus ruining the challengers business model and locks consumers into the telecom company’s cable movie offering. Thankfully, thus far Net Neutrality is not under serious threat in Europe. However, DRM certainly does nothing to make your Internet connection any faster. All is does is make digital media that you purchase over the Internet into an inferior product than it otherwise could have been.

One of the driving forces of the damaging policies is Viviane Reding, EU Commissioner for the Information Society and Media. She says “We have to make a choice in Europe: Do we want to have a strong music, film and games industry?” However the report issued goes on to call for the “establish(ing of) a framework for DRM transparency concerning, amongst others, the interoperability of different DRMs, and ensuring that consumers are properly informed of any usage restrictions placed on downloaded content…” The question remains, why create ‘usage restrictions’? Why not let the user just play their music how they want. It’s like selling someone a car and then letting them drive down only one street. It defies logic. Not to mention the that fact that every digital item you purchase will be more expensive as the cost of DRM will be included in each product. A more expensive and less functional product is not what the consumer wants. And the consumer is always right! They have rebelled against DRM before and they will rebel again. And the EU Commission wants to drag down European software houses and content providers with this sinking ship. With a ratification on the Lisbon treaty coming up in Ireland with guaranteed influx of the “No” vote protesters from neighbouring countries, we can only hope that Europe starts to give its citizens reasons to vote for Europe than against it.

For a more technical analysis of the announcement, as well as an open letter which you can sign that argues against the EU’s position, check out this link.