Read about:

Posts Tagged ‘Ruby’

Life advice in code

(Personal Development, Programming)

Live & Code has been largely about programming and life lessons. So, you can imagine that I was incredibly delighted to see these two combined in a small exchange on Facebook started by Reginald “raganwald” Braithwaite.

Life Advice in Code (raganwald)

Self-esteem expressed in Ruby

It’s a valuable life lesson made incredibly concise in my favourite programming language, Ruby. I leave the interpretation to the reader. It relates to some themes that I’ve already written about before and will probably write more about in the future.

LDAP-based RBAC with ActiveLdap and declarative_authorization

(Programming)

If you followed my previous tutorial on implementing pass-through authentication to LDAP with Authlogic, you might be wondering how it can be extended to give different permissions to members of different LDAP groups. ActiveLdap and declarative_authorization make this incredibly simple.
Read the rest of this entry »

Adventures in Ruby: When Constants Aren’t

(Programming)

I just squashed a bug that had me scratching my head for at least a good half-hour or so involving a class constant that kept on getting changed. Here’s the setup (anonymized so that I’m not exposing gooey proprietary secrets):

class WebTransaction
 
  # Base URL for transaction web service
  SERVICE_URL = "http://accountingservice.com/"
 
  def transaction_url
    url = SERVICE_URL
    url < < "VAL1=foo"
    url << "&VAL2=bar"
    url
  end
 
end

The class is meant to represent a transaction being posted against a rather odd web service that actually uses GET rather than POST for posting transactions (bad web service!). In my actual code, the URL parameters appended to the SERVICE_URL base would be determined on a per-object basis but I’ve simplified it here.

Here’s the punchline: SERVICE_URL was changing! Calls to transaction_url would keep on appending more variables to it. If you’re particularly clever with Ruby, you’ve already figured out exactly why. But if you’re scratching your head like I was, here are some hints:

  • In Ruby, constants aren’t. In fact, they’re really no different from variables except for the fact that Ruby detects that variable names in all-caps are probably supposed to stay constant and warns if you try to assign to them.
  • <<, for strings, will append to the end of the string.
  • Ruby strings are mutable. That is, operations on a string variable will usually be done in place, rather than returning a new string. (Method calls, on the other hand, are a different story!)
  • Assigning a String variable to another String variable will assign the reference. That is, the two variables will be pointing at the same object.

Hit the jump to see the solution to this little mystery…
Read the rest of this entry »

LDAP Pass-through Authentication with Authlogic and ActiveLdap

(Programming)

Today, I pushed a branch to my fork of authlogic_example: with-activeldap.

This branch shows a way of implementing pass-through authentication to an LDAP server using ActiveLdap and Authlogic, with just some small changes to the User and UserSession models.

Read the rest of this entry »

Where is why?

(Programming)

“Why The Lucky Stiff”, one of the most influential characters in the Ruby community, has simply vanished. His Twitter account, GitHub account, and most of his websites are gone without a trace.

Why The Lucky Stiff’s contributions to the Ruby community include “Why’s Poignant Guide to Ruby”, a book which many state was the reason they got into Ruby, Shoes, an easy-to-use cross-platform GUI toolkit with innovative online distribution features, and Hpricot, a very slick HTML parser that is also a joy to use.

Some believe that he has decided to move on from software development because his last tweet reads “programming is rather thankless. u see your works become replaced by superior ones in a year. unable to run at all in a few more.” Some believe that his accounts were all hacked. A few others believe that his anonymity has been compromised and that he has decided the destroy the pseudonym.

Wherever Why The Lucky Stiff goes from here, I hope he knows that there are so many of us who looked up to him and have him to thank for knowing the joy that is programming in Ruby. He will be sorely missed.

A Rails Puzzler

(Programming)

While I refuse to call this “magic”, the following has been confusing me for a long time now and I’ve finally decided to post it to my blog and see if anyone else gets it.

It turns out that ActiveScaffold and YARD don’t play nice together. In particular, if YARD has previously been loaded (say, to define a Rake task for it), ActiveScaffold initialization will fail with the following error:

uninitialized constant Helpers::ControllerHelpers

Using --trace and following the source code, I find out that this is happening during ActiveScaffold’s initialization, particularly at this statement:

ActionController::Base.send(:include, ActiveScaffold::Helpers::ControllerHelpers)

Debugging the ActiveScaffold initialization code yields this baffling result:

>> ActiveScaffold::Helpers
=> Helpers
>> ActiveScaffold::Helpers::ControllerHelpers
NameError: uninitialized constant ActiveScaffold::Helpers

It’s the weirdest thing that I’ve seen since I became a Rubyist and it is blocking me from using YARD to generate the documentation for my current Rails project. Unfortunately, cutting out ActiveScaffold isn’t going to fly because the deadline for initial release is so close and so much functionality is implemented using it already. It wasn’t my choice; if I had my way, I might never use ActiveScaffold ever again.

On “Magical” Ruby and Rails

(Programming)

Giles Bowkett wrote a post which, at the surface, seems to be a harsh criticism of the way that Pythonistas and, in particular, Django developers view Ruby and Rails but is actually much more general — he simply wanted to point out that the entire notion of calling language/framework features “magic” is silly for programmers, who should prefer to be rational than superstitious.

Read the rest of this entry »

Future Ruby – Day 3

(Programming)

Sunday, July 12th, 2009

While the previous two days had already blown my mind, it seems as though the best had been saved for last.  The day’s talks started with Collin T. Miller giving us his thoughts on how we can move away from text as the primary way of encoding computer programs and move towards other encodings that more closely resemble the domains in which we are trying to solve computing problems. While I found his ideas interesting, I don’t think I can agree with his notion that text should be replaced as the primary encoding for programs. I think that text is an excellent way of representing computer programs: it is concise, easy to manipulate, and easy to parse.

FutureRuby – Days 1 & 2

(Programming)

Edit: In my haste to post my write-up of these first two days of the conference, I didn’t do much in the way of linking and I forgot to write about one of the coolest things that happened on Saturday, the flying robot blimp. Bear with me as I edit this post to add some much needed links and visuals.

Friday, July 10, 2009

After work, I walked over to the Metropolitan Hotel to get my badge. My kit included a schedule, a large poster, a crimson t-shirt with black Russian-propaganda style Future Ruby logo, a bottle of water, a pack of matches, a patch with the Future Ruby logo on it (for sewing on to backpacks and the like) and a TTC pass valid for the length of the convention. All of this was stuffed inside of a rugged, dark green bag with the Future Ruby patch sewn on it. This is by and far the best swag I’ve ever received at a conference, ever.

After that, I got dinner and headed down to Unspace HQ for a wicked awesome patio party. Unspace HQ seems like an incredible place to work — prime location, lots of outdoor space, and a pretty nice collection of knick knacks, including a working pinball machine — but it is also an excellent space for a party. The highlight of the night for me was seeing two CF18′s doing a fly-by. Although I’m not a huge fan of military hardware, watching the way that they turned through the air was a unique experience.

I went home early to give myself enough time to commute home and get at least 5-6 hours of sleep for the next day.

GitHub Project Watch – 09/07/08

(Programming)

I’ve decided to create a new series of posts called “GitHub Project Watch” to highlight some of the projects on GitHub that I am watching. It’s kind of like GitHub Rebase, but with my own personal touch.

Here are some of the projects that I’m watching this week:

  • jmettraux/ruote: an open source workflow engine built with Ruby. I might be using this for a project I’m working on. Also see jmettraux/ruote-web2 for a demonstration of how to integrate ruote with Ruby on Rails.
  • brynary/webrat: automated acceptance testing with Ruby. It can simulate a simple browser on its own or drive a real browser via Selenium. Apparently there’s some work in progress on integrating with Watir and Celerity as well.
  • radiant/radiant: RadiantCMS, the lightweight web content management system for Ruby on Rails. I’m contributing a Japanese translation, the current version of which is currently available in the official i18n branch. (also see kbingman/radiant and enricob/radiant)
  • chriseppstein/compass: As I wrote previously, Compass is gaining new features at an incredible rate. It now sports improved Rails integration, Blueprint 0.9, an extension system, and asset hosts support. As an added bonus, it no longer depends on edge Haml; it will work with the newest stable release of Haml, 2.2.0. This is one of the most watched repositories on GitHub for a reason — if you’re not already using this, try it today!

I’m sure that I will hear of even more awesome projects at Future Ruby.