Read my latest article: Six days to complete the Rails hosting survey (posted Thu, 24 Apr 2014 14:36:00 GMT)

Hot OSCON Nights

Posted by Mon, 01 Aug 2005 02:55:00 GMT

I am heading to Los Angeles later this week to go to a wedding, Magic Mountain, and a meeting with a client. As my plans were being focused on whether my girlfriend would drive from Portland to L.A. or fly, I wasn’t prepared to make the commitment to sign up for OSCON sessions. We finally bought tickets as I reminded myself that I don’t enjoy sitting in the car for 18-22 hours in the hot summer.

So, aside from the exhibit halls and possibly helping out PDXLUG with the booth that we arranged, I’m not going to be doing much with OSCON. I am however hoping to head over to FOSCON on Wednesday evening. It will be nice to meet some more of the local Rubyists ( I still haven’t made it to a meeting yet…) and people like Matz, DHH, and other Ruby & Rails superstars will be there.

It’s currently pretty hot in Portland. I’m not a huge fan of heat (one of the main reasons why I opted to move out of California 5+ years ago in the first place). If you’re in Portland for the week and want to meet up with me for coffee, a beer, or some good vegetarian food… send me an email. :-)

Welcome to Portland!

The legacy of databases with Rails

Posted by Tue, 26 Jul 2005 04:20:00 GMT

As I have had way too much experience with working with horribly ugly and outdated database schemas, I find myself wanting to add new interfaces, but can’t just drop their old schema as other applications rely upon it.

Let’s say that you have an old table that looks like this:

mysql> DESCRIBE client_comment;
+---------------------+--------+------+-----+---------+----------------+
| Field               | Type   | Null | Key | Default | Extra          |
+---------------------+--------+------+-----+---------+----------------+
| client_comment_id   | int(8) |      | PRI | NULL    | auto_increment |
| client_comment_body | text   | YES  |     | NULL    |                |
+---------------------+--------+------+-----+---------+----------------+
2 rows in set (0.00 sec)

In this example, I took the privilege of making the example only two fields, now imagine that this table has over 20-30 fields and they all have client_comment_ in front of the actual string that is of important. Who wants to type all that out over and over? Also, we all refer to this table as the table that holds customer notes, which doesn’t really match what they originally named it. No, we can’t just renmae the table, stuff relies on this structure. But for a new Rails interface, we’re going to tweak our model quickly to interact with the same outdated table in a cleaner fashion.

The first obvious thing is that we need to create a model called customer_note.rb.

class CustomerNote < ActiveRecord::Base
end
Next, we’ll tell the model that it’s table name is client_comment, rather than customer_notes like it is going to expect it to be. While we are at it, let’s take a quick moment to define the primary key for this table, because id is not what they picked when they first made the table.
class CustomerNote < ActiveRecord::Base

  set_primary_key "client_comment_id" 

  def self.table_name() "client_comment" end

end
With this, we can already start interacting with our table as if it were called customer_notes.
$ ./script/console
Loading development environment.
>> CustomerNote.create(:client_comment_body => "hello world")
=> #<CustomerNote:0xb7a02cfc @new_record=false, @attributes={"client_comment_body"=>"hello world", "client_comment_id"=>39}, @errors=#<ActiveRecord::Errors:0xb79a4508 @base=#<CustomerNote:0xb7a02cfc ...>, @errors={}>>

Okay, now we want to interact with the field client_comment_body as just body. We want to be able to get and set this value, so we’ll add the following methods to our model.

  def body
    read_attribute "client_comment_body" 
  end

  def body=(value)
    write_attribute "client_comment_body", value
  end

The first method allows you to access (get) the value of client_comment_body with CustomerNote.find(1).body. The second method handles when you (set) the value for body, it then provides the client_comment_body attribute with the value. Technoweenie on IRC helped me get this trimmed down from my original version.

In the end, you have this:

class CustomerNote < ActiveRecord::Base

  set_primary_key "client_comment_id" 

  def self.table_name() "client_comment" end

  def body
    read_attribute "client_comment_body" 
  end

  def body=(value)
    write_attribute "client_comment_body", value
  end

end

Then, you can do save yourself some typing by accessing the field with the alias that you provided. :-)

$ ./script/console
Loading development environment.
>> a = CustomerNote.new(:body => "Hello World!")
=> #<CustomerNote:0xb78c6ffc @new_record=true, @attributes={"client_comment_body"=>"Hello World!"}>
>> a.save
=> true
>> a
=> #<CustomerNote:0xb78c6ffc @new_record=false, @attributes={"client_comment_body"=>"Hello World!", "client_comment_id"=>40}, @errors=#<ActiveRecord::Errors:0xb7890d6c @base=#<CustomerNote:0xb78c6ffc ...>, @errors={}>>
>> b = CustomerNote.find(40)
=> #<CustomerNote:0xb788ccd0 @attributes={"client_comment_body"=>"Hello World!", "client_comment_id"=>"40"}>
>> b.body = "Goodbye...cruel... world." 
=> "Goodbye...cruel... world." 
>> b.save
=> true
>> CustomerNote.find(40)
=> #<CustomerNote:0xb7886330 @attributes={"client_comment_body"=>"Goodbye...cruel... world.", "client_comment_id"=>"40"}>
>> CustomerNote.find(40).body
=> "Goodbye...cruel... world." 
>>

Feel free to send me tips if there is an even better way of doing this. :-)

Cheers… and enjoy!

RubyURL This!

Posted by Fri, 22 Jul 2005 23:33:00 GMT

I fixed a bug in the RubyURL This!

A few people reported problems, and I added a catch to prevent those who accidently click on it while on the rubyurl.com page. ;-)

http://rubyurl.com/

(link/instructions on page)

Working in Portland coffee shops and cafes reviews, part 1

Posted by Thu, 21 Jul 2005 21:10:00 GMT

Since I have found myself sitting in cafes and coffee shops a lot, I thought that I would give a quick and dirty review of a few that I frequent.

Costellos Travel Caffe – My first trip here was to meet Rael Dornfest of O’Reilly for lunch. I had a vegan tomato soup that day and have been in love with that place since. Free wifi + good food = Costellos. They have a nice, short menu, with soups, sandwiches, and salads. In regards to the coffee, they have the best soy mochas out of this list of cafes. You can also enjoy a good foreign beer or glass of wine. They always run videos on the 2 large widescreens on the walls, of photographs and videos from different places around the world. It’s usually soundtracked to some instrumental music… for example, the last time I was in there, I heard Sigur Ros and Lemon Jelly while video showed. It’s a pretty cool place and I need to thank Rael for inviting me there. :-)

My only problem with working there is that it does attract a lot of traffic and finding a good seat isn’t always realistic. You can get lucky… but finding a spot with a power outlet isn’t always guaranteed…infact, you’d best charge up before getting there… as I’d be the guy in the corner with the plug in use already. ;-)

Urban Grind (NE) – This is my morning-to-noon place. They do serve food, but I haven’t actually tried their sandwiches or soups yet. I enjoy their coffee and go here the most. The place is in a big warehouse and it has many tables that are perfect for working at. My girlfriend often comes with me and we sit side by side on our laptops and have enough space to spread out a bit. Free wifi as well and tons of extension cords for people to plug in. There is more of a regulars atmosphere there. The same people show up each day and it’s very calm. My only wish is that they stayed open later than 4 PM. The one in NW has later hours, but that would require me to drive or bus to the other corner of town. I also prefer the laid back nature of NE/SE in contrast to the NW area. Music typically heard include, bjork, interpol… just to name a few. I usually have my headphones on anyways.

Fireside Coffee Lodge – Located in SE Portland, this is the farthest regular spot that I go to. Why would I go so far? They are open 24 hours. Yep, 24 hours of free wifi and coffee… how can you pass that up? When and if I get the urge to work at 2 AM, I can head there and have a good and quiet time. It has several outlets for juicing your laptop and has some tastey coffee drinks. (might I suggest the Almond Joy…) I have been going there for several years with PDXLUG, which is where we hold our monthly meetings. The seats aren’t as comfortable and the tables aren’t either.. but that doesn’t matter when you need that 3:15 AM coding fix and you want to get out of the house for a bit. I spent a lot of time there this last spring when my girlfriend was finishing up here semester in college doing homework. Music doesn’t really play here too often and if so, it’s usually one of the girls at the counter playing NPR.

Redwing Coffee & Baking – Honestly, sitting here.. this is my first time here. What provoked this entry was that I felt that someone should provide a quick and dirty list of places in Portland to work on. So maybe I will work on a site for that in the future and such… as opposed to just how good the food/coffee is… how easy is it to spend 6+ hours in it? Laptop batteries don’t last that long.. and as there seems to be only one power outlet..and I got lucky to snag it. So, I don’t know if this place is ideal for working more than a few hours in. They are currently playing Neil Young… and I’d guess that older stuff like Young, Dylan, and maybe some other 60s/70s stuff would be common here. It’s quite warm in here too as they are baking food in the back. It makes for a nice smell, but when it’s 90~ degrees F outside, it doesn’t cool you down much. They’re open to 8 PM and look like they have a good menu for vegetarians, (like me).

UPDATE: They have free iced tea refills… that’s great!

On a side note, it just started to sprinkle. My day just got a little better. :-)

So, there is my list of a few common places that I go to. I will post more in the near future, but thought that I would start off with the last 4 places that I have been to. I intend on trying more and will continue working on this list.

back to writing… and to my hummus plate.

Portlanders… do you have any places to suggest for working at? I’d like to continue my search for the perfect away-from-the-office cafe.

RubyURL shortcut for your toolbar

Posted by Tue, 19 Jul 2005 14:30:00 GMT

I realized that I never posted my bookmark for RubyURL.

javascript:void(location.href='http://rubyurl.com/rubyurl/remote?website_url='+location.href)

Just drag/copy this link to your toolbar.

RubyURL this!

Maybe if I get some time soon, I will work on a firefox extention, but for the time being, this is cross-browser friendly. :-)

The last time that I checked, there were about 1300 unique rubyurls generated. Maybe this will help drive up that count. :-)

The Passion of the Rails

Posted by Fri, 15 Jul 2005 19:50:00 GMT

I haven’t been able to post much the past few weeks. I finding myself sitting at wifi friendly coffee shops around Portland the past few weeks. I’ve been keeping busy with working on the book. :-)

If you’re in Portland and happen to find yourself bored during the day… come look for me in the cafes. I find myslf working at Urban Grind (NE) usually in the mornings.. at least 3 days a week now. The office has been a bit hot (especially in the afternoon)... and the coffee shop has better coffee.

Older posts: 1 2