Archive for the ‘programming’ Category

Hash#fetch

Tuesday, August 30th, 2011
{}.fetch(:a) { 0 }
=> 0

I think it’s really beautiful. Oh, and it’s Ruby, btw.

Update: this is even better:

{}.fetch(:a) { {} }
=> {}

hookup is the shit!

Monday, June 6th, 2011

This is simply amazing:

$ g pull
Already up-to-date.

$ g co edge
Switched to branch 'edge'
==  AddFileTypeToSong: migrating ==============================================
-- add_column(:songs, :file_type, :string)
   -> 0.0048s
==  AddFileTypeToSong: migrated (0.1380s) =====================================

$ g rebase master
Current branch edge is up to date.

$ g co master
Switched to branch 'master'
==  AddFileTypeToSong: reverting ==============================================
-- remove_column(:songs, :file_type)
   -> 0.1674s
==  AddFileTypeToSong: reverted (0.1679s) =========================

Oh, and it will bundle automatically for you as well, so don’t hesitate and hookup your Rails project!

On Heroku

Monday, February 21st, 2011

While Heroku is nice and all, it suffers from the same disease as every other hosted-for-you solution:

$ git push heroku
(...)
-----> Gemfile detected, running Bundler version 1.0.7
(...)

$ bundle --version
Bundler version 1.0.10

It’s a whole three patch versions behind! Now I don’t really know (and maybe don’t even really want to know) what has changed between .7 and .10, but I can easily imagine things braking precisely because those minor inconsistencies in Bundler versions.

And sure, I could downgrade to .7, but to do that just because of Heroku? Thank you, but no. I want to ride the latest.

You can quote me on that

Monday, October 25th, 2010

What every software project accumulates the most over the years is its ever-growing TODO list.

Mocha. The stubbing library

Tuesday, May 26th, 2009

This example (shortened here):

class Order
  def shipping_cost
    total_weight * 5 + 10
  end
end

require 'test/unit'
require 'rubygems'
require 'mocha'

class OrderTest < Test::Unit::TestCase
  # illustrates stubbing instance method
  def test_should_calculate_shipping_cost_based_on_total_weight
    order = Order.new
    order.stubs(:total_weight).returns(10)
    assert_equal 60, order.shipping_cost
  end
end

and this snippet (emphasis mine):

The more interesting discussion deals with whether to mock or stub your database-backed model. One upside is speed: This test case will not hit the database at all. Another is independence. I completely isolate the code under test to the controller layer.

convinced me that there just might be some treasure to be found beyond the Test::Unit. And I know that it's just the tip of the iceberg.

My github repository

Wednesday, March 11th, 2009

To anyone interested, here’s the link to my github repository with all of my open-source projects. Most of them are my own Rails plugins, but I host the latest development version of the WP Movie Ratings plugin. Without any further ado, here it is:

http://github.com/pjg

Rails and Merb together

Wednesday, December 24th, 2008

Or putting it in another words: Merb will be merged into Rails to become Rails 3.0. Is it 1st April just way too soon or what? – was my first thought the moment I’ve read it on the Ezra’s blog. But then I’ve read the official announcement and… it kind of turned out to be true. Surprised I was, definitely. I haven’t really jumped on the whole Merb bandwagon. Sure, I was planning to try out Merb in the (rather distant) future. Now it seems I won’t have to. Merb supposedly did lots of things better than Rails (modularity, less dependencies, more lightweight, faster) and those things are to be incorporated into Rails. Will see how this pans out.

Exciting times. Definitely exciting. Nice Xmas gift.

Lucky to be a Programmer

Wednesday, July 30th, 2008

From the great article on our fluorishing craft, Lucky to be a Programmer by Gustavo Duarte:

For the past few weeks I’ve been working with a fellow developer on a project that required an all-out programming effort. It’s done now, so we’re back to a regular schedule, but when people hear about the crazy hours they often say they’re sorry. They really shouldn’t be. I would never do this often, or for long periods, or without proper compensation if done for an employer, but the truth is that these programming blitzkriegs are some of my favorite periods in life. Under the right conditions, writing software is so intensely pleasurable it should be illegal.

(via Ryan Dahl)

Programming IQ: 55

Wednesday, July 30th, 2008

Headline skimmer

It was a rather hard programming quiz. On the other hand 55 points is exactly 55%, so I have passed. Barely, but still…

On static typing

Tuesday, May 13th, 2008

Static Typing

The above picture comes from Steve Yegge‘s Egomania. There’s also his great post Dynamic Languages Strike Back. Both recommended reads.