11.28.07
Posted in Uncategorized at 1:41 pm by JohnB
The success of the Ruby on Rails web framework is somewhat based on its ability to soothe the pain caused by the not-so-rapid development process of other, so-called “enterprise-ready” frameworks. But Rails is not the only Ruby web framework, and not the fastest one for initial prototyping(*). The faster (more rabid?) ones I’ve looked at:
- Camping. From the the quirky mind of why-the-luck-stiff (no other name given) it inspires absurdly fast development (and absurdity!).
- Sinatra. Some people who have tried Camping have moved on to Sinatra - it has a clean syntax and a simple metaphor (Sinatra attends events) and is supported by a larger team.
Its hard to imagine what faster development would look like - maybe a web interface for defining Camping or Sinatra event handlers? Code the app directly from the browser!
(*) Footnote: Note that I use the word “prototype” because that is all I have done with them - I see no reason they couldn’t scale as well as Rails or any other web framework.
Permalink
11.18.07
Posted in health at 11:16 am by JohnB
I’m learning how to use my body, with the help of Amira, my Alexander teacher. The Alexander Technique has a number of techniques for reminding us that (a) we are usually working harder than we need to and (b) what we think we are doing is not always what we are actually doing. This latter aspect is known as “Faulty Sensory Awareness” because, although we may think we are standing up straight, any observer (or ourself looking in a mirror) can tell that we’re leaning one way or the other.
This became very clear to me last week as I was swimming laps. When kicking a length on my back, I tend to believe I’m looking straight up at the sky. Although I don’t really need my goggles in this position I usually have them on anyway - I can see the beautiful sky better. A side benefit of wearing the goggles is that, if I splash, I don’t get water in my eye. Last week I happened to be kicking on my back with my goggles off and noticed that my left eye was getting a bit of water in it, while my right eye was dry. Just to verify, I made sure that it happened in both directions down the lane - that it wasn’t due to my neighbor’s wake in the next lane. Nope. Unless the pool was tilted, it was me.
Although I thought my nose was pointed straight up, and it certainly felt “normal”, the water was telling me that I was ever so slightly tilted to the left!
So, if you’ve ever wondered about whether your body could work better than it does, give Amira (or any Alexander teacher) a try. As I always say: “She hasn’t killed me yet!”. (BTW: that is an inside joke with Amira - she wouldn’t allow that quote on her website so I had to come up with a different one)
Permalink
10.11.07
Posted in ruby at 3:09 pm by JohnB
A non-programmer friend recently asked me why I liked Ruby so much. I asked him for a simple task that I could write in Ruby and we came up with a pyramid - from a single “a” to 26 “z”s. So I showed him this one-liner:
"a".upto("z") { |c| puts c * (1 + c[0] - "a"[0]) }
And then showed him the same program in C:
#include "stdio.h"
int main( int argc, char **argv )
{
int loop = 0;
for( loop = 0; loop < 26; loop++ )
{
int innerloop = 0;
for( innerloop = 0; innerloop <= loop; innerloop++ )
{
printf( "%c", 'a' + loop );
}
printf("n");
}
return 0;
}
Enough said.
a
bb
ccc
dddd
eeeee
ffffff
ggggggg
hhhhhhhh
iiiiiiiii
jjjjjjjjjj
kkkkkkkkkkk
llllllllllll
mmmmmmmmmmmmm
nnnnnnnnnnnnnn
ooooooooooooooo
pppppppppppppppp
qqqqqqqqqqqqqqqqq
rrrrrrrrrrrrrrrrrr
sssssssssssssssssss
tttttttttttttttttttt
uuuuuuuuuuuuuuuuuuuuu
vvvvvvvvvvvvvvvvvvvvvv
wwwwwwwwwwwwwwwwwwwwwww
xxxxxxxxxxxxxxxxxxxxxxxx
yyyyyyyyyyyyyyyyyyyyyyyyy
zzzzzzzzzzzzzzzzzzzzzzzzzz
2/6/2008 Update: it might be shorter and more clear like this
("a".."z").each_with_index { |c,i| puts (c * (i + 1)) }
Permalink
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
08.22.07
Posted in Uncategorized at 4:00 pm by JohnB
Just thought it would be a good time to post an example of
my javascript code - ugly and insecure, but sufficient for this game among friends.
Permalink
08.07.07
Posted in ruby at 3:04 pm by JohnB
Have you ever loaded a file into irb, only to find that it scrolls endlessly? Its easy to do by accident:
log = File.open('bigger_file_than_you_expected.log') { |f| f.read }
But a simple trick can limit the output to a single useful line:
(log = File.open('bigger_file_than_you_expected.log') { |f| f.read }).length
=> 5066612
Now you can happily slice and dice your data without all the useless output. And yes, it applies to any operation that would spit out more data than you really want to see.
Permalink
08.05.07
Posted in ruby at 11:41 pm by JohnB
I recently came across Davey Shafik’s nice little Tooltip.js script - and I love it. I love it so much that I’m adding it as context-sensitive help all over the site I’m building. My needs are fairly simple: just some sort of pseudo-icon I can use next to any visual element to show that help or warning information is available. Every aspect can (of course!) be styled any way you want it.
To gain consistency and ease of use I wrote something that isn’t an actual Rails plug-in but is more of a… drop-in. Just drop in three files and you’re ready to roll. There are a few ways to add the tips to your views, but the easiest way is to just add
<%= Tooltip.help name %>
or
<%= Tooltip.alert name %>
to show a highlighted icon. The ones I currently use are html pseudo-icons (? for help and ! for warnings) but they can just as easily be image tags (and will be, as soon as I can find some appropriate icons).
Finally, to get the tip data to be formatted into hidden divs you need to add this to the bottom of your view (or, ideally, your layout):
<%= Tooltip.content %>
Thats nearly all there is to it. The only remaining task is to add these three files:
Eventually I’ll make it publicly available, but if you’d like a copy sooner just send me a note at my gmail address: john dot baylor.
Permalink
08.03.07
Posted in Uncategorized at 10:52 pm by JohnB
Sites like slashdot post articles for users to comment on. On a regular basis someone posts as soon as they can, just so they can claim the position of first post. But I’m above all that. I won’t sully such sites with my one-upmanship - I’ll do it on my own blog! So there.
First!
Permalink
Next entries »