01.25.08

Using Ubuntu

Posted in Uncategorized at 3:18 pm by JohnB

I’ve heard that dual-booting Ubuntu linux was easy but its really true. I’m now running Ubuntu and it was as easy as various blog posts have said. The longest step in the process was defragmenting the drive before repartitioning with Ubuntu. There are a few issues remaining around using the data on the Windows partition from Linux, but on the whole I’m very happy with the switch.

[Update 1/29/2008: the network is inconsistent.  Upon a boot or un-hibernate it may be completely incapable of finding my router - but then later it is fine. I'll continue trying to track it down... using the Windows OS!] 

01.14.08

Xkcd Titles

Posted in ruby at 1:26 pm by JohnB

I’ve just noticed the geekily hilarious xkcd comic and one of the funniest aspects is that each comic has a ‘title’ attribute (the text that pops up when you hover your mouse over the image) that is often as funny as the comic itself. However, the length of the title often causes it to be truncated in my browser (Firefox 2.x, which probably has an obscure show-entire-title setting). Rather than arduously do a ‘view source’ on each one (or figure out the Firefox setting), I have Ruby do it for me. And for you if you want:

# xkcd.rb
# extract all the titles from xkcd comics since they
# tend to be too long to fully show in the browser

# USAGE: ruby -rubygems -rxkcd.rb -e 'Xkcd.new.show_all'

require 'open-uri'
require 'hpricot'

class Xkcd
  DOMAIN = 'http://xkcd.com/'

  def show id = 343  # 343 is the NSA/RSA one
    begin
      @hp = Hpricot.parse( open( "%s/%d/" % [DOMAIN,id.to_i] ) )
      (@hp / :img).each do |el|
        puts "%4d: %s" % [id.to_i, el[:title]] if el[:title]
      end
    rescue
    end
  end

  def show_all
    0.upto(400) do |i|
      show i
    end
  end
end

01.12.08

Jumping on the Bandwagon

Posted in musings at 3:06 pm by JohnB

I just have to wonder: who were the first two people to have “died in a blogging accident“?

12.17.07

Another High-Traffic Rails Site: catalogchoice.org

Posted in Uncategorized at 6:12 pm by JohnB

Its getting a lot of traffic and seems pretty snappy:

http://www.catalogchoice.org/

So yes, Virginia, Ruby and Rails do scale.

11.28.07

The Perception of Scarcity in a Climate of Fear

Posted in musings at 1:56 pm by JohnB

I was playing Blokus today, where competition is driven by the scarcity of space on the game board, and realized that the perception of scarcity is often more prevalent than actual scarcity – and thus we needlessly hobble ourselves by limiting things that are abundant. Similarly, our fear that something might happen to us (crime, identity theft, terrorism, etc. – whatever monsters we see on the evening news) forces us to add locks and protections that mostly just result in making it hard for us to access our own belongings and data and websites.

The context for this discussion is a website (nameless, sorry) that I’m interested in working on. The startup site, yet another type of social network, holds the promise of allowing for some very interesting and powerful interactions – but unnecessarily limits its users as it guards scarce server resources and data security. Furthermore, and I’m going out on a limb here, I suspect that these mis-perceptions are one of the reasons this startup has had difficulty in raising much-needed funds. Some examples:

  • Users are automatically logged out after a few idle minutes, with no option of changing the time period before auto-logout (or choosing “Keep me logged in” for single-user computers). This seems a bit draconian given that there is nothing accessible on the site that couldn’t be gathered in other ways – no bank statements, social security number or mother’s maiden name.
  • A PDF document containing the public profile data for your social circle can be generated for off-line access, but only by a subset of the social circle and only for a short period of time. I think this is intended both for security and to guard scarce resources (such as server time and bandwidth). The former concern is misguided – anyone receiving the PDF can circumvent security by immediately sending it to bad people – which is unstoppable once you provide off-line access). The scarcity of server time or bandwidth can be overcome by delegating it to someone else such as Amazon’s ECC or S3 services.
  • New people can be invited to the social circle, but only by a small initial set of users – and those invitations expire relatively quickly. Its unclear why this decision was made, but I suspect it was due to some perception of scarcity or security. All it appears to do is add yet another unnecessary barrier to entry.

In spite of these issues, and others, I’m still captivated by the underlying ideas that it represents and by what it could become in the future. Hopefully I can rapidly prototype my vision for an improved site and use it as a starting point to land a dream job.

Even More Rapid Development

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.

11.18.07

Faulty Sensory Awareness – Water Never Lies

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)

10.11.07

Iterators – enough of a reason for Ruby

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)) }

09.29.07

d efine for twitter – step 1

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!

09.21.07

RJS Error: TypeError: $(element) has no properties

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++.

« Previous Page« Previous entries « Previous Page · Next Page » Next entries »Next Page »