Archive for the ‘Tech’ Category

script.aculo.us multiple drag and drop

Wednesday, October 22nd, 2008

Today I added multiple selection ability to to the scriptaculous sortable, a feature that is still missing on the main branch. Since this is a byproduct of the project I’m currently working on, it’s mere a demo of how to do it and not an actual patch for scripty. But maybe it could help you, if you have to do something similar… The demo is available at http://simplificator.com/scriptaculous-multidrag/.

Time zones in Rails 2.1

Monday, September 1st, 2008

Rails 2.1 has pretty good support of Time Zones. It’s possible to save user-specific time zones. So if your users are from different zones, you can display the output in the corresponding zone of the user.
To set a default time zone, add config.time_zone in environment.rb. For the output, set the current time zone in before filters via application controller.

def set_zoneTime.zone = @user.time_zone if @userend

If you display timestamps in ActionMailer, you must set the Time.zone option within the ActionMailer class. Otherwise, the default settings of the database are taken (Time zone: UTC)

Rails provides nice helper methods to work with time zones. A useful method is in_time_zone(). It presents a time in any time zone.
>> t = Time.now
>> t.in_time_zone('Bern')=> Mon, 01 Sep 2008 14:47:00 +0200

Several rake task helps you to find out the possible zones:
rake time:zones:all
rake time:zones:local
rake time:zones:us

New Gem Released

Tuesday, August 26th, 2008

New ? Ah… not really. Would be fond to say that TLS support for ActionMailer is new. Anyway we packed up the code which is floating around on the web to add TLS support to pre Ruby 1.9 projects. Just for convenience. Find it on github.

rwebthumb RubyGem updated

Tuesday, August 5th, 2008

We’ve added support for the Easythumb API to the rwebthumb gem. Just grab the latest version from github (sudo gem update simplificator-rwebthumb) and see the README. rwebthumb is a ruby wrapper for the Webthumb API.   

Resources:

We have two masters

Wednesday, July 30th, 2008

We are slowly moving our projects from our svn repository to github. In that process we had to move a private repository from one github account to another (pulling and pushing again), still maintaining the svn part.Funny situation ocurred today. After I pulled, merged and pushed my local repository back to the new github account I have two masters!I don’t exactly know how I did this. Who knows what I get when I pull the master branch now?Two masters on github Update: After I wrote this post, some background task seems to have tidied up for me. Phew. One master. 

dry your controllers

Friday, July 25th, 2008

Tired of the rererepeating controller code for your resources ? Enter resource_controller / resource_this / make_resourceful.
Three plugins doing one thing. Each little different, with it’s own syntax and quirks and strengths.
Instead of writing the same 7 actions (new, create, edit, update, index, show, destroy) over and over again you just let the plugin handle this tedious work.

While we’ve worked with make_resourceful in another project (and we’re happy with it) we decided to take a look at the different options again.
I’m by no means an expert and have not compared them with a checkbox list. I’ve just played around with the plugins and then went for resource_controller (perhaps because it looked like the one with the most activity). It supports nested resources, singleton resources (this branch), namespaces and has various hooks to change the behaviour (how resources are loaded, before/after actions) and thats all we need :-)

Any comments on which of these plugins you prefer and why ?

Lighttp and Fileupload on Windows

Monday, July 14th, 2008

A customer of us deploys a Rails app on a Windows platform. We are using

It was a pretty straightforward process to setup and configure this stack, following one the online documentations. How happy we were when everything worked and we could hit our Rails app from the browser. Everything ? Ahhhh… not exactly. File upload did not work properly. Only one out of 10 uploads would succeed, the other would fail after around 60 seconds. The browser should an “Connection Timed Out” error message, the access and error logs of Lighty did not give much information.When we had IIS rewrite to one mongrel directly then the upload worked, so the problem was somewhere with Lighty. Digging around in the Lighttpd forums and documentation brought up following configuration options which could be relevant for fileupload:

  • server.max-request-size (defaults to 2 GB so there should be no problem)
  • server.upload-dirs (Make sure this is a valid Windows directory with write permissions)
  • server.network-backend (Unclear which backends are available for Windows)
  • server.max-read-idle (defaults to 360 seconds)
  • server.max-read-idle (defaults to 360 seconds)

We solved our problem by setting the server.network-backend to ‘writev‘ (a bit obscure but hey… it worked)

RubyGem for webthumb

Thursday, July 10th, 2008

Webthumb is a service to create thumbnails from websites (descriptive name, isn’t it…). It creates different sized thumbnails by default and you can request custom sizes.It offers an API to access it’s services and we wrapped up some code i wrote while on vacation and bundled it as a gem.The code is still a bit clumsy (as i wrote it on vacation :-) ) but it works nice for us. There is already another ruby wrapper for the API but it is not available as a RubyGem and does not expose some of the latest webthumb functionalities so we decided to write our own library. Josh gave us some extra credits so we could develop the API. Thanks. The gem is available on Simplificator’s github repo. To install do following:
sudo gem update --system (in case you are not yet on version 1.2.0 or higher)
sudo gem sources -a http://gems.github.com (only once)
sudo gem install simplificator-rwebthumb

To create thumbnails:
require 'rubygems'
require ‘rwebthumb’
include Simplificator::Webthumb
# main access point for the Webthumb API
wt = Webthumb.new(’YOUR API KEY HERE’)
job = wt.thumbnail(:url => ‘http://simplificator.com’)
job.write_file(job.fetch_when_complete(:large), ‘/tmp/test.jpg’)

For more info check the README file and (currently) the source code. All the features from a the request element are supported but currently not documented. I’ll look into that in some days.If you want to use the Gem you’ll need an account for webthumb. You’ll get 100 free credits every month so it’s easy to try it out.

git Cheat Sheet

Thursday, July 10th, 2008

If you are not a git-ninja (like me) then this cheat sheet by Zack Rusin might come in handy.And: You know you’ve been on vacation for too long if you can not find this fç%& power switch on the printer.

Don’t write from scratch

Wednesday, July 9th, 2008

It’s several years now that I am out of school. I have a BS in software engineering and run my own company. I was taught stuff about compilers, queues, patterns, languages, mathematics, datastructures, … you name it. Asked what I was not learned in school I would answer: “how to fight the urge to rewrite everything”.

To a die hard software writer “rewrite it” seems like the perfect solution to every problem. The silver bullet to all failures in IT. After all the others are just a bunch of loosers losers and I am Mr. Super-Design-Software-Pattern-On-The-Edge-Flavour-Of-The-Day-Framework-User. Just tear everything down and start from scratch. WRONG. WRONG. WRONG. Whenever you have to touch a software system, be it for enhancements or for fixing bugs, and you feel like you should dump the whole codebase and just start from scratch (after all it’s so easy to do it. It probably takes 3 days) step back and take a deep breath. The authors of this system were not just a bunch of idiots. They had reasons to do it the way they did:

  • The business is not as easy as you might think at a first glance
  • Technical restrictions from inside or outside
  • The system evolved over time
  • Your state of the art framework/programming language/tool was not available when the system was written
  • They knew less than you know now (unlikely…)

So think twice. And then think again. Wouldn’t a tiny update or bug fix do ? You need to add new features and the original system was written in Cobol/Fortran/Delphi and you do not have a clue of these languages ? Perhaps you can add the new stuff with your super-duper framework/language and just integrate it. Find someone who knows the language, chances are hiring someone is less expensive as you rewriting the whole system.Yes. This is something I was not taught in school. This was something I had to find out for myself. I made my own errors … not that i tried to write Mozilla from scratch… it was on a smaller project. Lessons learned!

Resources: Years ago I read an article on this topic. I think it was it in Joel’s book ? Anyway. Here it is: Things you should never do, Part 1