Posts Tagged ‘tip’

Use rails-footnotes to open files in NetBeans from Firefox

Friday, January 16th, 2009

Here is how to use rails-footnotes with NetBeans on linux!

Thanks to José Valim we have a nice new plugin for better debugging of Rails applications! In his blog post he describes how to open links to files on your hard disk with notepad++ on windows. I adapted this idea for opening files with netbeans on linux, and here is your way to go:

open about:config in firefox and add:

  • string network.protocol-handler.app.editor with content ~/.editor.rb
  • bool network.protocol-handler.external.editor and set it to true

create the file ~/.editor.rb and make it executable:

touch ~/.editor.rb && chmod +x  ~/.editor.rb

And here is the content:

#!/usr/bin/ruby
file = ARGV.first.split('file://').last.split('&').first
line = /\&line\=(\d+)/.match(ARGV.first)[1] rescue 0
`"/path/to/your/netbeans-dir/bin/netbeans" "#{file}:#{line}"`
`wmctrl -a "NetBeans IDE"`

install wmctrl

sudo aptitude install wmctrl

We’ll need this to give focus to the NetBeans window.

Use to_money to convert a string to an integer

Monday, November 3rd, 2008

Just a quick note: You can use the following code in your helpers/application_helper.rb to convert a string to an integer in your Rails application:

class String
  def to_money
    fee = self.match(/(\d+)(,|.?)(\d{0,2})/)
    if %w(, .).include?(fee[2]) # 56,99 1.00 5,-
      return "#{fee[1]}#{fee[3].to_i.to_s.ljust(2, '0')}"
    elsif fee[1] && fee[2].blank? # 5
      return "#{fee[1]}00"
    end
  end

  def to_money!
    self.replace to_money
  end
end

Now you can do some fancy stuff like the following:

"12 Euro".to_money => 1200
"12 Dollar".to_money => 1200
"12.00 Dollar".to_money => 1200
"12,00 Euro".to_money => 1200
"12,- Euro".to_money => 1200
"1200 Euro".to_money => 120000
money = "12,8 Euro"
money.to_money!
puts money # => 1280

You can read about the motivation why to use integer in favor of decimals in the database here: 7 Top Tips for Coding With Currency.

Please select an appropriate title when you write emails!

Saturday, September 20th, 2008

More and more often I get emails from customers which just hit reply in their email-account to write me something. So far, so good. The problem is, that the contents don’t belong to all prior emails. That sucks and I will explain you why:
I am using Google Mail a.k.a. Gmail (not in Germany btw) which has the nice feature of threaded conversations. You’ll find a nice explanation about this killer-feature here, and shortening this: All emails of one subject, whether I send it or receive it, are one thread. There are no folders received emails and sent emails. So when somebody sends me an email by hitting reply I get this email in the appropriate thread because it has the same subject.
Please differ the subject of your emails, when you are writing something that belongs to a completely different subject!

Other subjects that give me headaches are something like this: “I thought…”, “Can you”, “Problem” or “Help!”. This isn’t new to anyone visiting internet-forums from time to time knowing what a netiquette is. It says, e.g. to select a good subject for your posts! This is the same for emailing! Write good subjects like this: “Problem with module x”, “Module y is to slow” or “Question regarding project z”

Please think about this the next time you email, thanks!