Skip to content
Sep 18 09

Seth Godin lists the questions to ask before building a website

by Topper

Seth’s Blog: Things to ask before you redo your website

I think these are perhaps the tenth and eleventh questions you should ask, not the first two. Here’s my list of difficult and important questions you have to answer before you spend a nickel:

Sep 10 09

CouchDb: Replication halts between two databases and results in a hung erlang process

by Topper

We were seeing a json error in the couchdb logs. Apparently 0.9.1 (because of MochiWeb) doesn’t like certain UTF characters. Unfortunately, this causes replication to totally hang. That’s a bummer. It looks like it’s been patched:

http://issues.apache.org/jira/browse/COUCHDB-333

However, that’s not in the 0.9.1 release.

Sep 10 09

Confused about CouchDB changes API?

by Topper

If the couchdb book confused you regarding the changes api that supposedly exists:
http://books.couchdb.org/relax/reference/change-notifications

I think that’s a 0.10 release feature (and not yet in 0.9.1). I stumbled upon this API which seems to do something very similar: http://wiki.apache.org/couchdb/HTTP_Document_API?action=show&redirect=HttpDocumentApi (scroll down to “all_docs_by_seq”).

Sep 9 09

Avoding the “Dog pile” effect

by Topper

How to avoid the dog-pile effect on your Rails app | Plataforma Blog

Imagine that in a certain hour, this page on your application receives 4 requests per second on average. In this case, between the first request and the query results being returned, 5 seconds will pass and something around 20 requests will hit your server. The problem is, all those 20 requests will miss the cache and your application will try to execute the query in all of them, consuming a lot of CPU and memory resources. This is the dog-pile effect.

Nice article on how to prevent multiple requests from triggering the same long-running query.

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]
class ::String
# This below fixes a bad memory leak in ruby 1.8.6
# http://blog.edhickey.com/2008/12/03/memory-leak-in-ruby-186-string-class/
alias :non_garbage_split :split
alias :non_garbage_gsub :gsub
alias :non_garbage_gsub! :gsub!

def split(char)
holder = char
non_garbage_split(holder)
end

def gsub(*args, &block)
if args.size == 1
non_garbage_gsub(args[0], &block)
else
non_garbage_gsub(args[0], args[1], &block)
end
end

def gsub!(*args, &block)
holder = args[0]
args[0] = holder
non_garbage_gsub!(*args, &block)
end
#end memory leak fixes
end
[/ruby]

Aug 13 09

Fast RFC 3339 date processing in javascript

by Topper

UPDATE: This article is translated to Serbo-Croatianlanguage by Anja Skrba.

UPDATE: Removed dead Motionbox link. I work at Amicus now.

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). [js] Date.prototype.setRFC3339 = function(dString){ var utcOffset, offsetSplitChar; var offsetMultiplier = 1; var dateTime = dString.split("T"); var date = dateTime[0].split("-"); var time = dateTime[1].split(":"); var offsetField = time[time.length - 1]; var offsetString; offsetFieldIdentifier = offsetField.charAt(offsetField.length - 1); if (offsetFieldIdentifier == "Z") { utcOffset = 0; time[time.length - 1] = offsetField.substr(0, offsetField.length - 2); } else { if (offsetField[offsetField.length - 1].indexOf("+") != -1) { offsetSplitChar = "+"; offsetMultiplier = 1; } else { offsetSplitChar = "-"; offsetMultiplier = -1; } offsetString = offsetField.split(offsetSplitChar); time[time.length - 1] == offsetString[0]; offsetString = offsetString[1].split(":"); utcOffset = (offsetString[0] * 60) + offsetString[1]; utcOffset = utcOffset * 60 * 1000; } this.setTime(Date.UTC(date[0], date[1] - 1, date[2], time[0], time[1], time[2]) + (utcOffset * offsetMultiplier )); return this; }; [/js]

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.
[js]
Message = MBX.JsModel.create(“Message”);

MBX.MessageView = MBX.JsView.create({
model: Message,

onInstanceCreate: function (message) {
var li = this.buildLi(message);
$(“message_list”).insert(li);
},

buildLi: function (message) {
var li = new Element(“li”, { id: message.primaryKey() });
li.update(message.get(‘body’));
li.updatesOn(message, “body”);
return li;
}
});

// This will add the ui element
var message = Message.create({ body: “this is my body!” });

// and if you change body, the ui will automatically update as well
message.set(‘body’, “some other body”);

[/js]

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?