Top picks from my bookshelf

While trying to streamline my growing book collection, I thought to do a post on the books that have been most useful. So here goes:

bookilicious
View the full Image

Posted in General | Leave a comment

Fireworks Resources and Tutorials

I’ve got a confession to make – I don’t do Photoshop very well.
In spite of my best intentions, I can’t seem to wrap my head around all the stuff expert designers take for granted. I guess I’ve got the mind of a coder. The fact that I can take a finished graphic and convert it into lovely XHTML and CSS code but would rather be coding PHP, Perl, Ruby, (insert new flavour of the month here) seems to attest to this.

Fireworks is another story. This absolutely simple-to-use application is where I spend most of my time when I need to work with graphics. The learning curve is a lot easier and for the 10% of stuff I need to do that it can’t handle, I’ve got friendly designer, Photoshop-expert friends.

That said, Fireworks related information on the web a little thin. The following tutorials and resources have been really helpful and hopefully they will be useful to you too (if you’re the Fireworks type).

Tutorials

Resources

Posted in Web | 1 Comment

F1 2008 looking to be a blast

The 2008 Formula 1 season has started and the first race was absolutely smashing. For real.

Brit Lewis Hamilton qualified at pole position and went ahead to win the race but that’s not the best part of this year’s first race.
In my view, the highlight is the introduction of rules designed to make the races less dependent on electronics aids. The consensus then is “out with technology”.

  • Traction control is gone (a system which helps limit rear wheel spin or loss of traction when excessive throttle or steering is applied by the driver).
  • Engine assisted braking is also out (in the simplest terms, a form of anti-lock braking – but not quite).
  • Goodbye Launch Control (a system that allows the driver at the start of the race and at pit stops achieve optimal getaway without spinning the wheels).

The results? Out the 22 cars at the beginning of the Australian Grand Prix, only 7 finished the race. No more safety nets when the driver overcooked it.
Watching the drivers battle to hold the cars when the rear-end threatened to step out of line was a real joy to watch. Now that’s what I call racing.

These changes have a strong parallel with the current emphasis on designers and developers knowing how to hand-code rather than relying on Dreamweaver and friends to do the ‘dirty’ work.

Can’t wait for the Malysian race next weekend. Meanwhile, I’ll go have a drink on Lewis.

As an aside, these technologies have been making their way from Formula 1 cars into production cars. I wonder if that’s going to stop.

Posted in General | 2 Comments

What’s with all the ruby frameworks?

The Rails vs PHP debate has been on for ages with the standard answer being “You can’t compare Rails to PHP – Rails is a framework and PHP is a language. Compare it to CakePHP… or CodeIgniter… or Prado… or Symphony… or…”.
There are now so many PHP frameworks available it’s becoming increasingly difficult choosing one and sticking to it.

Rails has been the preferred Ruby framework for a while now and just until recently the other available frameworks were not mainstream. Moving from another language to Ruby invariably meant moving to Rails. Apparently, all that is changing.

Doing a search for Ruby frameworks brings up the following:

Obviously Ruby’s fast catching up with PHP.
The positive side is the debates will now become “Ruby vs PHP” like they should have been in the first place.

Posted in Web | 8 Comments

From PHP to Rails… and back

CodeIgniter has been my PHP framework of choice for a while now. I’ve churned out numerous sites based on the framework and even have my own CMS built on CodeIgniter.

I have tried out other frameworks (CakePHP, Symphony, Solar) but still came back to CodeIgniter due to its flexibility, extensive documentation and portability. Everything was fine and dandy until I decided to convert one of my (non-critical) internal apps to Rails just to try out the framework. I went from zero Rails experience (bar all the screencasts) to a fully working (small) app in three days.

Granted, my knowledge of CodeIgniter came in handy (in the end all MVC frameworks are the same at heart) but Rails has got so much convenience built-in that development is a breeze. Also, ActiveRecord (a true ORM implementation and radically different from the CodeIgniter flavour) is an absolute dream.

Fast forward a couple of weeks and back “in the real world of shared hosting accounts” here I am back to coding with CodeIgniter and it’s a real drag. The issues:

  • CodeIgniter validation is long-winded and after using the Rails one-liners in the models for validation this is becoming a chore.
  • ActiveRecord in CodeIgniter is really nice to use but after my experience with a true ORM and the ease of manipulating data with it I’m sold.
  • CodeIgniter requires some code which (in retrospect) is actually redundant. Having to assign views manually for every controller method is a case in point.

However, I’m pleased to say my preference for CodeIgniter is back and stronger after a couple of tweaks to try and solve some of these issues. The launch of version 1.6.0 of codeigniter also came at the right time as some of the tweaks depend on features previously absent from CI.

The changes:

  • Ditched OBSession: I have been using OBSession as the session library instead of that built into the CI core. I had a lot of issues prior to the switch. However the new version has some new features built-in (notably flash variables) and after a couple of days testing the applications seem to be working fine.
  • Extended the Validation Class: I ran into this post and the included library was really helpful in cutting down the number of steps involved in validation.
  • ActiveRecord: There’s an ORM implementation of ActiveRecord in the CodeIgniter Wiki and it basically suited my needs but its performance was not consistent. It did work on my Slicehost VPS but not on the MediaTemple GridServer or a WHM dedicated box. However, I didn’t bother to troubleshoot this after seeing the size of the objects being loaded.
    I then decided to check out CakePHP but this post pointed out that the cakePHP ORM does not use objects entirely, like Rails (and the CI mod) do.
    So I made a version of the CakePHP ORM for CI and it’s working fine for me. Problem solved.
  • Helpers: I also added a couple of custom helpers (like the h helper in rails for escaping data).
  • Views: My view folder is organized like the Rails view folder with a folder for each controller and a view file for each method named the same as the method. I extended the controller (created a library called MY_Controller) and all the application controllers extend this. If a view file exists, it is loaded into the main application layout (just like in Rails). However a view file is not required for every controller.
    I still have to call a render() method at the end of every controller though.

I am still tweaking this and as soon as all the bugs are ironed out I’ll show some code.

So in a nutshell, Rails made my PHP better! Ironical?

Update: I just tried out CakePHP again (for the first time after coming back from Rails) and it’s the closest PHP could come to Rails. I should use it on an actual project to get a real feel for it.

Posted in Web | 1 Comment

Restful Authentication with rails 2

I recently had to build an authentication system into a project and seeing as the restful authentication plugin was getting such buzz, I decided to try it out.

The problem was, most of the information I found on the internet was dated and I had to make a couple of changes to get it to work on Rails 2.0. This site and this forum post were really helpful. This post documents the steps I took (or rather, the steps I’ll take next time I use it) to get the plugin working. It assumes you already have a rails application running and want to add authentication to it.

  • Install the plug-in
    Open up a console window and navigate to the root of your application.
    Use script/plugin to install the plugin.

    ruby script/plugin install http://svn.techno-weenie.net/projects/plugins/restful_authentication/
  • Run the generator
    The generator sets up your controllers, model, views and observer as well as modify the routes.rb file (sets up session and users as resources). The session controller is used for signing in and out of the system while the user controller takes care of the rest.If you do not need a user activation system built into the system, type the line below:

    ruby script/generate authenticated user sessions

    If you need a user account activation system, use the line below. The rest of this post will assume the system includes user activation (the system is a lot simpler without user activation enabled).

    ruby script/generate authenticated user sessions --include-activation
  • Run the migration
    The system also generated a migration file. Run the migration with:

    rake db:migrate
  • Modify the routes file
    Open up config/routes.rb and add to the named route section:

    map.activate '/activate/:activation_code', :controller => 'users', :action => 'activate'
    

    While the routes file is still open, add more named routes (giving the user actions nice, friendly urls)

    map.signup '/signup', :controller => 'users', :action => 'new'
    map.login '/login', :controller => 'sessions', :action => 'new'
    map.logout '/logout', :controller => 'sessions', :action => 'destroy'
    
  • Add an observer (required for user activation emails)
    Add an observer to config/enviroment.rb (within the Rails::Initializer.run block) :

    config.active_record.observers = :user_observer
    

    At this point, the basic system should be working. Start up your development server and go to http://localhost:3000/signup. You should see the sign up form.
    Also try http://localhost:3000/login to confirm it’s fine.

  • Set up ActionMailer (required for user activation emails)
    The rails config/environment.rb file includes a Rails::Initializer.run block and prior to Rails 2, configuration code went in there.
    With Rails 2, there’s now a directory (config/initializers) where seperate, discreet bits of configuration are placed in files of their own.
    These are automatically loaded after plugins are loaded when Rails starts up.Create a new file called mail.rb in the config/initializers directory (you can actually call the file anything you like). SMTP setting will go into this file.
    Rails 2 also changed the variable for ActionMailer settings from server_settings to smtp_settings
    Place the following into the mail.rb file:

    ActionMailer::Base.delivery_method = :smtp
    ActionMailer::Base.smtp_settings = {
    	:address => "mail.example-domain.com",
    	:port => 25,
    	:domain => "www.example-domain.com",
    	:authentication => :login,
    	:user_name => "user@example-domain.com",
    	:password => "secret"
    }
    

    :address and :port – Determines the address and port of the SMTP server you’ll be using. These default to localhost and 25 , respectively.
    :domain – The domain the mailer should use when identifying itself to the server (usually the top-level domain name of the machine sending the email).
    :authentication – One of :plain, :login or :cram_md5. Should be omitted if the server does not require authentication. Also omit :username and :password options if you omit this parameter.
    :username and :password – Mail account login credentials. Required if :authentication is set.

  • Modify the activation email parameters
    Open the production and development configuration files, config/environments/production.rb and config/environments/development.rb respectively.In the development config file:

    SITE_URL = "localhost:3000"

    and in the production:

    SITE_URL = "example-domain.com"

    You need to restart the server for these settings to take effect.Open app/models/user_mailer.rb. Change:

    @body[:url]  = "http://YOURSITE/activate/#{user.activation_code}"

    to:

    @body[:url]  = "http://#{SITE_URL}/activate/#{user.activation_code}"

    Change:

    @body[:url]  = "http://YOURSITE/"

    to:

    @body[:url]  = "http://#{SITE_URL}/"

    Change the setup_email block settings (ADMINEMAIL and YOURSITE) to your desired settings.Open the email template files (app/views/user_mailer/activation.html.erb and app/views/user_mailer/signup_notification.html.erb) and modify as desired.

    And that’s it. The system should now be working.

    Note: You need to include flash[:notice] and flash[:error] in your templates or layout to view the status messages e.g. just before the <%= yield %> line in app/views/application.html.erb, type:

    <%= flash[:notice] %>
    <%= flash[:alert] %>
    

Update: Need help with using the plugin in your view or controller? Go here.

Posted in Rails | 59 Comments

Springloops – stressless subversion

We’ve been using Springloops for a couple of months now and all I can say is ‘Wow!’.

Springloops claims to be “a unique source code management tool focused on web development teams. It allows you to code in parallel and share your code safely concentrated on results, not on lost changes or overwritten files”. It delivers. Working from home was never this slick and it removed the need to set up our own version control server.

Springloops is a hosted service and the amount of storage space and number of projects you get depends on what plan you sign up to. There is even a free account giving you up to 10Mb of storage and 3 projects. However, I think the sweet spot is the ‘ Garden’ plan. With this plan (and all higher plans) you get the automatic deploy option and we use this to deploy any code we commit to our staging server via FTP.

The interface is well laid out with the dashboard showing recent account activity and links to your projects. You can also set up users and restrict their access to specific projects.

This service has become integral to our workflow and I can’t recommend it enough.

Update: Since we signed up for Springloops we’ve seen a couple of other hosted version control systems. Beanstalk and Versionshelf look promising.

Posted in Web | 3 Comments

Giving up on mongrel_cluster on windows

That’s it! I’ve given up trying to deploy a Rails app with capistrano from windows. Just spent two days trying to set this up (even tried cygwin) with no luck.

The solution? VirtualBox. I have just gone from installing Ubuntu server in a virtual machine to deploying the application in thirty minutes. It’s a bit long-winded commiting to subversion from windows and changing to the virtual machine to use capistrano but it works so I’m happy.

Why am I still working in windows? I ask myself that all the time but I’ve got so much stuff installed and set up on my laptop the thought of changing is depressing. Also use Visual Studio Express once in a while and that only works on windows.

Two thumbs up for VirtualBox.

Update: Finally got Capistrano to work on windows. About time!

Posted in Rails | 1 Comment