Broach: a Campfire API implementation for Ruby

Manfred Stienstra, 16 Dec 2009, 17:34 in releases and ruby (edit).

Today we released a lightweight implementation of the web API for 37signal’s Campfire called Broach. It’s really handy to use in your notification scripts.

Broach.settings = { 'account' => 'example', 'token' => 'xxxxxx' }
Broach.speak('Office chat', 'The filesystem on Server 1 is almost full!')

If you want to try it out, you can simple install the gem.

$ gem install broach

You can find more details on the GitHub project page. The source is documented so you probably want to start reading there.

No comments yet

Apprise

Manfred Stienstra, 01 Nov 2009, 20:47 in ruby on rails and releases (edit).

Last friday Eloy and I participated in the Ruby en Rails Rails Rumble 2009, we had 8 hours to write an application which helped developers find out more information about the dependencies in their Rails application.

Our submission is called Apprise. Apprise is a tool to check gem dependencies and external repositories for newer versions of the currently installed ones in your Rails application.

To be more specific, it looks for three sources of dependencies. Git and Subversion externals in vendor/plugins and bundled Gems in the Gemfile. Checking for Gem dependencies is delegated to Bundler. If you don’t use Bundler to manage Gem dependencies you will still see outdated externals and submodules.

Outdated dependencies are listed and you can decide to update the externals, submodules or gems.

$ apprise                 
Outdated dependencies
 * forestwatcher (Subversion external)
 * risosu-san (Git submodule)
 * miso (Gem)

If you want to try it out you can easily install the gem and run the command in the root of your Rails application.

$ gem install apprise --source http://gemcutter.org

Unfortunately we did not win, but our patch for Bundler to list outdated gems was pulled by Yehuda Katz right after the competition.

3 comments

Fingertips Rails Template

Manfred Stienstra, 29 Oct 2009, 16:48 in ruby on rails and releases (edit).

People are always curious how we build our applications, what gems we use, and how we do authorization. We’ve posted bits and pieces in the past but with Rails’ project template support we ran out of excuses to just show the codes.

You can find the code at GitHub, but a better way to check it out is to create a small app.

$ rails BookCase -m \
  http://github.com/Fingertips/rails-template/raw/master/fingertips.rb

As I’m typing this up I’ve noticed a hundred ways to improve the templates. If you have ideas or patches, please post them to the GitHub issue tracker.

1 comment

New OS, more pane! (Passenger preference pane v1.3)

Eloy Duran, 02 Sep 2009, 17:20 in ruby on rails, tools, releases, os x, and rubycocoa (edit).

As Snow Leopard was released, I saw lots of talk on the interwebs about the Passenger preference pane not working on the new kitten OS. Which frankly was to be expected, but unfortunately Apple had not supplied me with a developer seed. Maybe next time…

Oh by the way, fun fact! What I did find is that NOT having your application up-to-date for a new OS release is actually pretty good marketing stuff. The Passenger preference pane had about 380 watchers for a while, but during the last few days we (finally) reached 400 watchers! Thanks a lot guys! Can’t wait for the next OS upgrade so we can beat Passenger with their 776 watchers ;-).

Now where was I… Ah yes.

The pain involved in the update:

So in order to help everybody out as soon as possible, I’ve created a version which will work on both PPC and Intel machines, as well as OS X 10.5 and 10.6. This means that it will want to load System Preferences.app in 32-bit mode. But since many preference panes currently need that, we didn’t deem it a show stopper.

The real problem in getting the Passenger preference pane to run in 64-bit mode would be that System Preferences.app wants to use the Objective-C garbage collector. And rightfully so. But the only way to support this easily would be to use MacRuby, which as of yet is not stable enough. But expect the next version of the preference pane to use MacRuby and be a happy 10.6 citizen.

One last note: Apple Help in a preference pane, ugh. As ironic as it may sound, there’s not much help out there, either in the form of documentation or on how to debug it. Expect a separate post on this.

Change goodies:

  • Mac OS X 10.6 support, although still in 32-bit mode:
    • Bundle RubyCocoa.framework in the preference pane. (Ticket #2 & #8)
    • Made the Apple Help work on both 10.5 and 10.6.
  • Added a check at launch, which verifies if all your application hostnames are registered in the hosts database (Directory Services). If not, add them. Obviously this is especially handy for people upgrading from 10.5 to 10.6, but also comes in handy when editing vhosts by hand.
  • Added preference pane Info.plist keys so the help shows up in the Help menu.
  • Use proper capitalization for the Apache conf ”Directory” directive.
  • When the user changes the path to an application, also replace this in the @user_defined_data string. (Ticket #4)
  • Various source cleanups.

Most users probably want to download the “stable” 1.3 release.

If you’ve added your hostnames to /etc/hosts in the meantime, then you can safely remove those again as the preference pane will add these to the hosts database on startup.

If you understand why stable has been quoted, you can track development and contribute on: http://github.com/alloy/passengerpane.

Please report any bugs you may find at: http://github.com/alloy/passengerpane/issues.

24 comments

Passenger preference pane v1.2

Eloy Duran, 03 Dec 2008, 17:47 in ruby on rails, tools, and releases (edit).

To get the latest version, please see the Passenger preference pane page.

X-Mas came early this year ;-)

Checkout the changelog:

  • Rack support. Thanks to Kematzy for the original suggestion/work.
  • Fixed “issue” people had with the default non-vhost based directory not working anymore. Thanks to “spike” for debugging this.
  • Made the vhost config file extension configurable as well. Patch by Felipe Mathies.
  • Backported RubyCocoa + Ruby 1.8.7 fix. Patch by Grant Hollingworth.
  • Removed the “Allow mod rewrite rules” checkbox, we found it’s not worth the UI real estate.

Most users probably want to download the “stable” 1.2 release.

If you understand why stable has been quoted, you can track development and contribute on: github.com/alloy/passengerpane

Please report any bugs you may find at: fingertips.lighthouseapp.com/projects/13022

4 comments

Unichars 0.2 released

Manfred Stienstra, 24 Nov 2008, 22:09 in ruby on rails and releases (edit).

Unichars is a simple wrapper around Glib2 Unicode functions. You can use it to speed up certain methods on Unicode string. Currently supported are: upcase, downcase, reverse, and size. The cool thing about it is that it works seamlessly with ActiveSupport::Multibyte and it works great without ActiveSupport::Multibyte.

I guess Unichars is not a very exiting name like God, Vlad the Deployer, or Gerard Joling but I guess I’m not that kind of a guy.

You can install Unichars with Rubygems:

$ gem install unichars

Or you can fetch it from Github:

$ git clone git://github.com/Manfred/unichars.git
$ cd unichars
$ rake gem:install

With Rails

The examples in the README tell you how to use Unichars with Rails 2.1 or newer. I’ll just re-iterate how it’s done.

First you make sure you load the library, the easiest way to do this is with config.gem in environment.rb:

config.gem 'unichars'

Or when you dislike gems, you can just require it:

require 'unichars'

When you’re not using config.gem, you have to make sure ActiveSupport is loaded before Unichars, otherwise the Rails integration won’t magically work.

After that you have to tell ActiveSupport::Multibyte to use the Unichars class as proxy class. You can do that in an initializer or at the end of your environment.rb. I would recommend doing it in config/initializers/unichars.rb.

ActiveSupport::Multibyte.proxy_class = Unichars

Now all of Rails will automatically use the Unichars character proxy, you can also use it yourself:

'青山'.mb_chars.reverse #=> '山青'

Without Rails, but with ActiveSupport

require 'activesupport'
require 'unichars'
ActiveSupport::Multibyte.proxy_class = Unichars
$KCODE = 'u'

Other than that it’s similar to Rails:

'Sluß'.mb_chars.upcase #=> 'SLUSS'

A good time to talk about LC_CTYPE real quick. Note that Glib2 picks that up from your environment, so your results may vary depending on what it’s set too.

Without training wheels

require 'unichars'

If you don’t use ActiveSupport, you can still use Unichars because it comes with a light version of the Chars proxy. You will have to wire it yourself though:

class String
  def mb_chars
    Unichars.new(self)
  end
end

'Copy-®'.mb_chars.size #=> 6

Without anything

Finally, you can just use the Glib2 wrapper and roll your own solution:

require 'glib'
Glib.utf8_upcase('Comme des Garçons').upcase #=> 'COMME DES GARÇONS'

Questions?

If you have any questions or issues, please use the Github Wiki Wiki as much as possible. If you want to discuss anything you can find me on Freenode in #rails-contrib. Have fun with Unichars!

4 comments

ActiveSupport::Multibyte Updated

Manfred Stienstra, 23 Sep 2008, 13:47 in ruby on rails, unicode, and releases (edit).

Yesterday Michael Koziarski merged the updated version of ActiveSupport::Multibyte into Rails. The initial reason for the update was Ruby 1.9 compatibility but it turned into a complete overhaul. Not just the code, but also the documentation was revised.

For most people the only noticeable change is the move from String#chars to String#mb_chars. People relying heavily on ActiveSupport::Multibyte probably want to read on.

String#chars renamed to String#mb_chars

One of the initial reasons to use a proxy to access characters back in 2006 was to make Rails future proof in case Ruby got some kind of Unicode support on String. Unfortunately Matz decided to use String#chars for one of these features so we had to change the method name. People running on Ruby <= 1.8.6 will get a nice deprecation warning.

String#mb_chars now returns a proxy on Ruby 1.8 and returns self on Ruby 1.9.

Note that the Ruby 1.9 String class does not implement methods like String#normalize. We’re still trying to figure out how to approach this limitation. For now, you might want to do:

class String
  def normalize(normalization_form=ActiveSupport::Multibyte.default_normalization_form)
    ActiveSupport::Multibyte::Chars.new(self).normalize(normalization_form)
  end
end

No more automatic tidying of bytes

Multibyte no longer attempts to convert broken encoding in strings to a valid UTF-8. The String#tidy_bytes method still exists if you need this functionality.

Duck-typing aid

Strings are notoriously hard to duck-type because they include Enumerable, which makes them hard to differentiate from Arrays. Rails already had some duck-typing help in place for Date, Time and DateTime. We decided to implement the same thing on String and Chars.

'Bambi and Thumper'.acts_like?(:string) #=> true
'Bambi and Thumper'.mb_chars.acts_like?(:string) #=> true

So if you catch yourself using str.is_a?(String) please consider using acts_like?.

Different way of registering backends

Instead of registering a handler on the Chars class, you now set the proxy_class on ActiveSupport::Multibyte.

ActiveSupport::Multibyte.proxy_class = UTF32Chars

Note that this removes a level of indirection, which speeds up the entire Multibyte implementation quite a bit.

If you’ve implemented your own handler, please look at the implementation of ActiveSupport::Multibyte::Chars on how to convert it to work with the new implementation. In most cases this should be a trivial exercise. Don’t hesitate to contact me if you need help.

Overrideable default normalization form

The default normalization form can now be set on ActiveSupport::Multibyte instead of updating a constant.

ActiveSupport::Multibyte.default_normalization_form = :kd

See ActiveSupport::Multibyte::NORMALIZATIONS_FORMS for valid normalization forms.

1 comment

Passenger preference pane v1.1

Eloy Duran, 19 Sep 2008, 18:10 in ruby on rails, tools, and releases (edit).

To get the latest version, please see the Passenger preference pane page.

Yes yes, it’s update time!

This version comes with important fixes and some requested improvements. I’ll let the changelog speak for itself:

  • Honor custom environments that a user might have set.
  • Fixed problem with restarting Apache. After saving an application Apache should now automatically be restarted. Thanks to Ciarán Walsh.
  • Added support for ServerAlias and add those entries to the hosts db.
  • Reload the applications from disk when the preference pane is brought back to the front. Any changes made to the vhosts from elsewhere will be reflected in the UI.
  • Moved all hardcoded paths into a config module. Added a config for Apache 2 as installed by MacPorts. Thanks to Ciarán Walsh.
  • The host table list was editable. Thanks to Ciarán Walsh.
  • Fixed bugs in parsing custom user defined data in vhosts.
  • Create a tmp dir before touching restart.txt if none exists.
  • Replace underscores with hyphens in hostnames. Thanks to Bryan Liles.

Most users probably want to download the “stable” 1.1 release.

If you understand why stable has been quoted, you can track development and contribute on: github.com/alloy/passengerpane

Please report any bugs you may find at: fingertips.lighthouseapp.com/projects/13022

10 comments

Putting the pane back into deployment

Eloy Duran, 24 Jun 2008, 14:24 in ruby on rails, tools, and releases (edit).

To get the latest version, please see the Passenger preference pane page.

We blogged how using Passenger made development easier, but being the Mac User Interface Junkies we are, we’d like to take it one step further.

This was a great opportunity to play with preference panes in RubyCocoa. Thanks to Jason Foreman, and his repository of templates, I didn’t have to spend a lot of time finding out how to initialize a prefPane bundle.

It turns out that creating basic features with a mediocre interface (the default stuff you get from Interface Builder) can be done fairly quickly. However, making it look and feel like a preference pane from the “OEM fruit company” is a different story. Who would have thought?! ;)

Thijs doing interface design with the latest available technologies. Can you spot the advanced z-index technique he used? Hint: Starts with a P.

Anyways, back to the introduction; after roughly 2 weeks we give you an OS X System Preferences pane that will configure Apache and set up a local hostname for running any Rails application using Phusion Passenger. Getting your Rails app up and running is now a matter of seconds.

Most users probably want to download the “stable” 1.0 release.

If you understand why stable has been quoted, you can track development and contribute on: github.com/alloy/passengerpane

Please report any bugs you may find at: fingertips.lighthouseapp.com/projects/13022

Note that Passenger preference pane requires OS X 10.5.2 (or at least 10.5.0 and install RubyCocoa 0.13.2 yourself) and Passenger 2.0.1.

71 comments