Archive for March, 2007

Syntax .. Smintax ..

Last week I was called upon to write some Perl - something I haven't done since last fall. It was funny how as I was working on it, it started to come back to me. So I thought it'd be fun to compare my favorite languages a little bit:

Looks at how arrays are defined and the way I like to loop through them:

PERL:
  1. @books = ('Learning Perl', 'Advanced Perl Programming', 'Perl Best Practices');
  2.  
  3. foreach $book(@books) {
  4.   print "* $book\n";
  5. }

Foreach is actually an alias for "For" and some prefer that in this use because it makes it more readable. It also looks like php...

Now, for the language that has consumed my time the past 6 months...

PHP:
  1. $books = array('Pro PHP Security','PHP Cookbook','Pro PHP XML and Web Services');
  2.  
  3. foreach($books as $book) {
  4.   print "* $book\n";
  5. }

And.... here's ruby:

RUBY:
  1. books = ['Programming Ruby','Ruby Cookbook','Mr. Neighborly\'s Humble Little Ruby Book']
  2.  
  3. for book in books
  4.   print "* #{book}\n"
  5. end

I never actually used the for loop like that with an array, I usually use this version which is what the parser converts it to anyways:

RUBY:
  1. books.each do |book|
  2.   print "* #{book}\n"
  3. end

Fun stuff :)

Comments (1)

New Laptop

My large beast of a 17 inch Sager laptop is now a desktop. I opened it 1.5 weeks ago to have the hinge snap out on me, a month after the 1 year warranty! doh! I'd been wanting to get a smaller laptop since I'm on the go so much, but was juts waiting for the right time. The large laptop is still in good condition, just no good for transporting. So, Nick ordered me a new one and it arrived yesterday and I have it mostly configured.

The brand is Crown and I ordered from PowerNotebooks.com and its great. It came naked so I could install the windows I already own (decided not to get vista, mostly what I do these days is run linux in VMs) and not have a load of crap on it like aol, et al. Its a 2Ghz dual core with 2 GB memory and 80 gig hard drive. Plenty of space for my VMs - was a bit cramped on 40GB on my older one. Its weighs just 5.6lbs with battery and I think will work out great. Since I have destructive tendencies it seems, Nick got the 3 year warrenty for this one!

Comments

Optional Sidebars

For one of my projects, my layout includes optional sidebars on either side. I want to design this without tables.. so at first I thought something like this:

RUBY:
  1. <div id="leftside">
  2. <%= render :partial => "left_#{@controller.action_name}" %>
  3. </div>
  4. <div id="rightside">
  5. <%= render :partial => "right_#{@controller.action_name}" %>
  6. </div>

SO for index page, it will render the partials _left_index.rhtml and _right_index.rhtml ... but say if you don't want a side bar, then it can't find one... and you get an error. I would like to not have to resort to setting variables @left_sidebar =true @right_sidebar = false and have to do something like this:

RUBY:
  1. <% if @rightsidbar_on %>
  2. <div id="rightside">
  3. <%= render :partial => "right_#{@controller.action_name}" %>
  4. </div>
  5. <% end %>

Ideally I'd like a render_if_exist but I don't see anything like that in rails. Ideas??

Update

Almost as soon as I finished the post and sent to my friend Peter.. I decide to google for "render_partial_if_exists" and found this blog posting by Jeremy Hubert -- the exact solution! Peter was also in the process of adding a comment at the same time telling me with nearly the same solution. -- Check out Jeremys post, its awesome.

Comments

No Ruby Vacation

Turns out, that not even ruby was relaxing enough for my 3 day vacation.. I didn't do much of anything on the computer. Just took a break. I spent some time outside, ordered a bike..did alot of swimming and had some fun.Now, I'm back and ready to tackle work again.

Comments

Ruby Weekend

As some people plan vacations, I'm planning a Ruby weekend.

Today Friday, I'm going to get my day job projects worked on so I don't have to do any on the weekend, do any errands and other things today and clear the weekend! I will be working on a site for my mother's new Bakery/Coffeeshop! Save for going to the gym every day for a while, church on sunday and visiting with family on monday, I'm going to see how much I can get done in 3 days.

I'm always excited to see company's blogging about their progress, especially with development. I happened to see this post on the ROR Blog about Revolution Health. And here is their blog. Has some interesting things about their progress with Rails. Also, a friend of mine, Peter Harkins is starting his own company and is blogging about how he is using rails -- good tips to be had there also.

In addition to companies, I also like to follow independent consultants like Obie Fernandez, who is starting his own consulting company and is posting some interesting tips along the way.

Its companies and people like this that inspire me to work on extra projects, and I'll be keeping my eye open this weekend for any neat trick I discover on my "ruby vacation."

Comments