09.29.07
Posted in ruby at 2:55 pm by JohnB
For those of you who use twitter, you’ll likely recognize the separation of ‘d’ from ‘efine’ as intentional: ‘d’ means direct a message to another twitter user and ‘efine’ is the user you’re sending it to. Together I hope they connote ‘define’ because thats what they do. Sending
d efine ruby
to twitter should, if my twitter-bot works as intended, return a direct reply of
"A clear, deep, red, valued as a precious stone."
Which is a fairly accurate definition (even if it does leave out my favorite computer language).
So in this part I’ll describe the definition-grabbing piece, which queries wiktionary.org for the first definition. This first iteration is stupidly simple: read the entire page, parse its contents with the wondrous Hpricot tool, grab the first item from the first ordered list on the page and throw away any links. It sometimes gets odd or partial definitions so it will need improvement - but works great for the five minutes it took to write.
require 'open-uri'
require 'hpricot'
def efine word
open("http://en.wiktionary.org/wiki/#{word}") do |f|
(Hpricot(f.read) / "ol" / "li")[0].to_plain_text.gsub(/s*[.*]/,'')
end
end
That’s all. You’ll have to wait for the twitter-integration piece in my next post. I haven’t written it yet, but given the functionality in twitter4r, I doubt it will be much longer than the efine() method above. In fact, my usual peeve about Ruby is just that: it takes longer to describe the code than to write it!
Permalink
09.21.07
Posted in ruby at 6:11 pm by JohnB
I received this error message late yesterday while testing out RJS templates and link_to_remote(). I did a google search and didn’t find anything useful - some questions that were asked and never answered; one that said “rebuild your entire app”. Finally, I opened the page in another browser and it worked fine. huh?
doh! Rails nearly-seamless simplicity strikes again!
I had just changed my view code (.rhtml file) to include a new div that I wanted to be updated in an AJAXy manner. So I clicked the link in the browser (remember: this is AJAX - no page refresh) and expected my new div to be replaced with the neat new content. Nope. I had to do a decidedly non-AJAX page refresh so my browser would now have the neat new div - only then could the div be replaced.
Its so simple to swap between edit and test, edit and test, edit and test, that the few times you’re required to step out of the cycle seem like a huge hassle. But not when compared to every other development process I’ve used.
I had a similar experience with the routes.rb file. Unlike models and controllers and non-AJAX views, the routes.rb file only gets loaded when the web server starts. Stopping and starting the server fixed the problem - but I think I had to run into it multiple times before I realized what the issue was. A minor pot-hole on the smooth Rails path.
To mis-quote a bumper sticker: the worst day coding Ruby is better than the best day fighting C++.
Permalink
09.10.07
Posted in Uncategorized at 11:30 pm by JohnB
Last night’s Tech Nation program had an interview with Rob Levy of BEA. He had some deep insights into dealing with outsourcing companies. In essence, either make them as peers or at least treat them as peers. This is a refreshing change to what I’ve seen, not only when outsourcing, but when purchasing companies outright to be “business units” within the greater company. In the words of one friend who works at one of these subsidiaries, they feel like the “red-headed step child”. It definitely puts the sub in subsidiary!
Rob Levy made the point that once these places become free-standing entities, with enough work and resources to work independently, then its perfectly normal for them to treat the company headquarters as an outsourcee instead of a parent. I can’t imagine a lot of C-level executives (especially in my company) giving this type of free rein.
Whether you agree with him or not, its worth a listen…
[editor's note: when jotting down my initial notes for this post I found myself writing that they were treated "as if they were peers" - which just goes to show how deeply engrained this sort of thinking is. The headquarters has the illusion of control, but its only a offering from the employees - if you make the company too difficult or unstable to work at you just may find you've lost all your employees.]
Permalink