Mocha. The stubbing library

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.

Movies I've watched recently:

  • Push (2009) 3/5

    2009-07-02 23:55
    * * *

    Stupid but enjoyable.

    0.3
  • Zift (2008) 4/5

    2009-06-29 23:17
    * * * *

    Intriguing/entertaining.

    0.3
  • Che: Part Two (2008) 3/5

    2009-06-28 23:25
    * * *

    Boliva was difficult for Che and so is the second part of Sodenbergh's biopic. Not much happens, but apparently that's the way it was.

    0.3
  • Che: Part One (2008) 3.5/5

    2009-06-27 23:10
    * * * +

    Way, way too long. And a little bit boring, although entertaining, momentarily.

    0.3
  • Franklyn (2008) 3/5

    2009-06-27 00:09
    * * *

    Surreal & schrizophrenic trip to the Meanwhile city.

    0.3
  • Knowing (2009) 3.5/5

    2009-06-25 23:56
    * * * +

    Oridnary hollywood catastrophic flick. Stupid, sure, enjoyabe too.

    0.3

Movie ratings archive »

Debunking the stupidity myth

May 20th, 2009

From Why can’t we concentrate? by Laura Miller:

IQ tests have to be regularly updated to make them harder; otherwise the average score would have climbed 3 percent per decade since the early 1930s. (The average score is supposed to remain at a constant 100 points.) And IQ measures problem-solving ability, rather than sheer data retained, which has grown even faster over the same interval.

And here I was thinking all these years that we, as a global population, are in fact getting more and more stupid. People getting lower and lower grades, coming out of the Universities knowing less and less - it was all just an illusion. Average IQ is climbing. Steadily. Decade after decade we are getting smarter. It’s only that there are too few measures noticing it. Are IQ tests the only ones measuring it?

(via Brutto)

Electricity deficiency

May 15th, 2009

Yesterday was the day without google. Today was the day without electricity. Now without Google it felt like you didn’t have a right hand, but without electricity, it felt like being crippled. Nothing you could do. Not fun.

Negative consequences of Google’s ubiquity

May 14th, 2009

There is at least one. So while today Google is having some heavy troubles with its services, my angry neighbour (who has internet connection through my house) comes at my door saying the network is down.

- So what exactly is happening?
- My Mozilla is not loading.

Google: come back. World needs you.

Moore’s law, 40 years later, still in effect

May 14th, 2009

From the informal version of the Moore’s Law:

Moore’s original statement that transistor counts had doubled every year can be found in his publication “Cramming more components onto integrated circuits”, Electronics Magazine 19 April 1965. Moore slightly altered the formulation of the law over time, bolstering the perceived accuracy of Moore’s Law in retrospect. Most notably, in 1975, Moore altered his projection to a doubling every two years. Despite popular misconception, he is adamant that he did not predict a doubling “every 18 months”. However, an Intel colleague had factored in the increasing performance of transistors to conclude that integrated circuits would double in performance every 18 months.

December 15th, 2007: Seagate Barracuda 7200.11 500GB - 427 PLN

May 11th, 2009: Seagate Barracuda 7200.12 1000GB (1TB) - 419 PLN

Same price, twice the capacity. Roughly 17 months and one financial crisis later and the price per GB is almost exaclty two times lower. Incredible.

The case of Benjamin Button and 1080p

May 9th, 2009

From an imdb review:

Pitt plays the character at almost every age, but it’s almost impossible to tell when the CGI is being used on him. You know it’s there, obviously, but you can’t tell it’s being used. When the transition is just smooth enough for the Visual Effects to be retired, but just rough enough to use makeup, it’s absolutely perfect. If you’ve ever wanted to see Brad Pitt look 20 again, look no further, as the effects that make our actors young again (the same goes for Blanchett) are just as stunning as those that make them older.

Thing is with screen big enough and a 1080p source - you can tell the difference between Brad Pitt and CGI. And you can do it quite easily. Both old and young Benjamin look very much CGI alike. And it’s not that the effects are bad, because they’re not, it’s just that at this level of details (and face close-ups) you need to have your effect to be close to perfect. Seems we’re not quite there yet. The skin, the wrinkles, small hair covering the face, freckles, moles, every face feature - those are things you see and appriciate the most when viewing good HD content. And they make the biggest impresion. I know they did on me. They say animating a face is the hardest thing to do. At HD it’s ten times harder.

Sharing is Caring

May 4th, 2009

Sharing is Caring

So true, so true.

My github repository

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

Synecdoche, New York

March 7th, 2009

Great movie and a great quote (or rather a monologue):

Everything is more complicated than you think. You only see a tenth of what is true. There are a million little strings attached to every choice you make. You can destroy your life every time you choose. But maybe you won’t know for 20 years and you may never, ever trace it to its source.

And you only get one chance to play it out. And they say there is no fate, but there is, it’s what you create. And even though the world goes on for eons and eons you are only here for a fraction of a fraction of a second.

Most of your time is spent being dead or not yet born. But while alive, you wait in vain wasting years for a phone call or a letter or a look from someone or something to make it all right. And it never comes, or it seems to, but it doesn’t really. So you spend your time in vague regret or vaguer hope that something good will come along.

Something to make you feel connected.
Something to make you feel whole.
Something to make you feel loved.

And the truth is I feel so angry.
And the truth is I feel so fucking sad.
And the truth is, I’ve felt so fucking hurt for so fucking long.
And for just as long, I’ve been pretending I’m okay just to get along, just for…

I don’t know why. Maybe because no one wants to hear about my misery because they have their own. Well, fuck everybody.

- Amen.

The downsides of Virtuozzo when used with mongrel

March 3rd, 2009

The scenario goes more or less like this. You have your Virtuozzo powered VPS. You have your RAM limit. You have your mongrels behind nginx plus mysql taking on average 60-70% of your available RAM (quite sensible limit). Now imagine the server gets hammered (not necessairly your VPS). Load goes over 10 (or even over 50). Mongrels stop responding. Queue builds up (inside mongrels), mongrels consume more and more of memory. Load still over 10. Memory limit reached. One of the mongrels is killed by Virtuozzo (too bad if it was the only one). Load still high. At some point other mongrels stop accepting new requests (queue limit reached?) and when load goes down they are unable to process the built up queue. Effect: your website is returning a 500 error code and you have to manually restart the mongrels (they are hanged up). I’ve been seeing similar behaviour too often lately…

Possible solutions: xen (does not kill your children), passenger (spawns new children whenever needed), haproxy (prolongs the life of your children), god (brings dead children back to life).

I’m going with passenger for now, thinking about moving to xen in the future.