Skip to content
Sep 4 09

Fix string memory leaks in Ruby 1.8.6

by Topper

UPDATE: This is rails-incompatible... which sucks.

Ruby 1.8.6 leaks memory in some surprising places. Even gsub and split on the String class cause some bad headaches. If you're using Haml and 1.8.6 - you are probably in a bit of trouble.
Read more: http://blog.edhickey.com/2008/12/03/memory-leak-in-ruby-186-string-class/

However, simply overwriting the offending methods fixes this memory leak at least. With a weird caveat that you may not use $ variables (eg $1) in any blocks passed to gsub.

Re-read that last sentence... "boom".gsub(/b(.)/) {|m| $1.upcase} will NO LONGER work. Unfortunately... rails uses that syntax, making this blog post probably moot

RUBY:
  1. class ::String
  2.   # This below fixes a bad memory leak in ruby 1.8.6
  3.   # http://blog.edhickey.com/2008/12/03/memory-leak-in-ruby-186-string-class/
  4.   alias :non_garbage_split :split
  5.   alias :non_garbage_gsub :gsub
  6.   alias :non_garbage_gsub! :gsub!
  7.  
  8.   def split(char)
  9.     holder = char
  10.     non_garbage_split(holder)
  11.   end
  12.  
  13.   def gsub(*args, &block)
  14.     if args.size == 1
  15.       non_garbage_gsub(args[0], &block)
  16.     else
  17.       non_garbage_gsub(args[0], args[1], &block)
  18.     end
  19.   end
  20.  
  21.   def gsub!(*args, &block)
  22.     holder = args[0]
  23.     args[0] = holder
  24.     non_garbage_gsub!(*args, &block)
  25.   end
  26.   #end memory leak fixes
  27. end

Aug 13 09

Fast RFC 3339 date processing in javascript

by Topper

At Motionbox, we use a RFC 3339 time format in some data we return. Javascript doesn't natively handle this format with Date.parse. The only other blog post I've seen on the subject is this:

http://dansnetwork.com/2008/11/01/javascript-iso8601rfc3339-date-parser/

However, since that's a regular expression that's parsing on the string, it can sometimes be slower (but not toooo bad... 1000 iterations on the code from the blog post above took < 100 miliseconds in IE7 (~40 miliseconds in Firefox on a macbook pro).

I knew we could do better with splits. With my code below I got it operating 60% faster (so operations take 40% of the time from the code above).

JavaScript:
  1. Date.prototype.setRFC3339 = function(dString){ 
  2.                 var utcOffset, offsetSplitChar;
  3.                 var offsetMultiplier = 1;
  4.                 var dateTime = dString.split("T");
  5.                 var date = dateTime[0].split("-");
  6.                 var time = dateTime[1].split(":");
  7.                 var offsetField = time[time.length - 1];
  8.                 var offsetString;
  9.                 offsetFieldIdentifier = offsetField.charAt(offsetField.length - 1);
  10.                 if (offsetFieldIdentifier == "Z") {
  11.                     utcOffset = 0;
  12.                     time[time.length - 1] = offsetField.substr(0, offsetField.length - 2);
  13.                 } else {
  14.                     if (offsetField[offsetField.length - 1].indexOf("+") != -1) {
  15.                         offsetSplitChar = "+";
  16.                         offsetMultiplier = 1;
  17.                     } else {
  18.                         offsetSplitChar = "-";
  19.                         offsetMultiplier = -1;
  20.                     }
  21.                     offsetString = offsetField.split(offsetSplitChar);
  22.                     time[time.length - 1] == offsetString[0];
  23.                     offsetString = offsetString[1].split(":");
  24.                     utcOffset = (offsetString[0] * 60) + offsetString[1];
  25.                     utcOffset = utcOffset * 60 * 1000;
  26.                 }
  27.                
  28.                 this.setTime(Date.UTC(date[0], date[1] - 1, date[2], time[0], time[1], time[2]) + (utcOffset * offsetMultiplier ));
  29.                 return this;
  30.             };

Jul 21 09

Want to install Ruby 1.8.6 on Ubuntu 9.0.4?

by Topper

http://programmers-blog.com/2009/06/08/ruby-1-8-6-in-ubuntu-9-04-64-minimal

Jul 21 09

Problems install Curb on Ubuntu?

by Topper

http://axonflux.com/curb-install-problems-on-ubunt

Mar 19 09

Message Driven Beans in Jruby

by Topper

It was hard to find a lot of documentation on how to create a Message Driven Bean (MDB) EJB (for deployment into glassfish). Basically - I want to create a ruby app that receives messages and then does stuff with them. After tons of looking around I was able to finally put together one using NetBeans.

http://github.com/tobowers/jruby-mdb/tree/master

I don't have time now to go into the details... I, hopefully, will soon. However, edit the TesterMessageHandlerBean.java to change what message queue it listens to. Add or edit files in the src/conf/ruby directory to add ruby files.

Hope that helps... later I'll go into more detail about setting up glassfish and using OpenMQ.

I hate java, but this is a pretty damn nice way to deploy your ruby apps. Hopefully, this'll be a good start into letting us have ruby apps listening to OpenMQ in glassfish, but using jRuby.

Mar 15 09

Mamoo released as open source

by Topper

I just put the Motionbox Advanced Model Observer Observer (Mamoo) up on Github. It's a light-weight (13k), but fairly powerful framework for javascript built on top of Prototype and the Motionbox EventHandler.

It's fairly well documented and has a full suite of specs written in ScrewUnit.

Mamoo let's you stop thinking about the "glue code" you need on a client-side app - and start thinking like "when this happens, I want this to happen." - Event driven architecture in JS.

Checkout the readme for a romp through most of the features.

To whet your appetite, here's a really small, but useful app written with Mamoo.

JavaScript:
  1. Message = MBX.JsModel.create("Message");
  2.  
  3. MBX.MessageView = MBX.JsView.create({
  4.     model: Message,
  5.    
  6.     onInstanceCreate: function (message) {
  7.         var li = this.buildLi(message);
  8.         $("message_list").insert(li);
  9.     },
  10.    
  11.     buildLi: function (message) {
  12.         var li = new Element("li", { id: message.primaryKey() });
  13.         li.update(message.get('body'));
  14.         li.updatesOn(message, "body");
  15.         return li;
  16.     }
  17. });
  18.  
  19. // This will add the ui element
  20. var message = Message.create({ body: "this is my body!" });
  21.  
  22. // and if you change body, the ui will automatically update as well
  23. message.set('body', "some other body");

Assuming you have an ol with the id of "message_list" in your html page, now everytime you create a message, it'll get populated into the DOM.

I also put together a 15minute screencast that gives you a quick demo of a bunch of the features of Mamoo.

Nifty?

Mar 2 09

Boxes and Arrows: Bringing Holistic Awareness to Your Design

by Topper

Bringing Holistic Awareness to Your Design - Boxes and Arrows

We did not find any correlation with user satisfaction and those teams with the most specialized team members, one way or the other: some teams with the most specialization did well, and some teams did poorly. What we did consistently observe among teams that had high user satisfaction scores, was one characteristic that stood out above all the others—what we began to call shared, holistic understanding. Those teams that achieved the highest degree of shared, holistic understanding consistently designed the best web applications. The more each team member understood the business goals, the user needs, and the capabilities and limitations of the IT environment—a holistic view—the more successful the project. In contrast, the more each team member was “siloed” into knowing just their piece of the whole, the less successful the project.

Yes, yes yes. I now work for a company that believes in top-down and bottom-up understanding. I didn't always. I've always said that even the full-time janitor needs to understand the business goals in order to most-effectively do their job.

Mar 1 09

Phusion Passenger 2.1.1 beta released – looks great

by Topper

http://blog.phusion.nl/2009/03/01/phusion-passenger-211-beta-released-thanks-sponsors/

  • Support for Rails 2.3
  • Improved compatibility with other Apache modules, such as mod_rewrite
  • Ruby 1.9 support
  • Support for NFS setups
  • Various I/O handling and scaling improvements and fixes
  • Improved mod_xsendfile support.
  • Ability to disable Phusion Passenger for arbitrary URLs (PassengerEnabled option)
  • Improved application compatibility
  • Better cross-platform support (including OS X)
  • Non-interactive installer
  • Improved command-line admin tools
  • Ability to display backtraces for all threads
  • Improved security
  • More customization options for exotic systems/setups
  • Various usability improvements
  • Various other minor improvements and bug fixes

This thing is really starting to look like a great and simple way to deploy *real* apps.

Mar 1 09

Free git training course

by Topper

h/t to Ruby Flow:

Rubylearning.com is offering a free git and github training course. I don't have any personal experience with RubyLearning, but I hear good things and it might be a good introductory course for anyone that is just getting used to git.

http://rubylearning.com/blog/2009/02/10/git-and-github-a-free-course/

Feb 26 09

Hiivelogic: My Video and Slides from Acts as Conference 2009

by Topper

Hiivelogic: My Video and Slides from Acts as Conference 2009

Slides have a great quote from Steve Jobs and the talk is really great.

Saying no to features is really difficult, but hugely important. It's nice to see Dan Benjamin pushing developers to push back on requirements. It's hard sometimes, but the end-product is really worth it.

I think the part that he doesn't dig into deeply enough is true understanding of the market your product is going to end up in. Too many developers get caught up in the code and the computer aspect of their product. It takes a lot of work to try to understand the user and the market surrounding the user.

A lot of times understanding the product is harder than writing code, but it's something that everyone in your team really needs to spend a lot of time educating themselves on in order to create a successful product.