November 16, 2008

Rspec book announced

So, after more than a year of voices about it, it looks that the pragmatic programmers finally announced a book about rspec. The title will be available on april of the next year and I don't know if there will be a beta version.

Solution of project Euler #1

This is the first of a series of articles about project euler, a set of mathematics problems of incremental difficulty to be solved with your preferred programming language. You can find more about this on the project website.

PROBLEM N 1
This is the announcement of the first problem:
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.

Find the sum of all the multiples of 3 or 5 below 1000.

Solution using Ruby
The solution above is extremely simple and readable, which is why I love ruby and use it in my every day work:

def is_a_multiple_of_3_or_5?( n )
  n % 3 == 0 || n % 5 == 0
end


counter = 0
  
3.upto( 999 ) do |n|
  counter += n if is_a_multiple_of_3_or_5?( n )
end


puts counter

Solution using Erlang
I'm totally new to Erlang, but I've worked to a one-line solution using a comprehension list:

Result = lists:sum([ N || N <- lists:seq(1,999), N rem 3 == 0 orelse N rem 5 == 0 ]).

Basically, I create a list of all numbers under 1000 which are either multiples of three or multiples of five, then I've calculated the sum of all those numbers with the native procedure lists:sum.

Solution using Scheme
I love scheme, although I've never done that much with it:

(define total
(lambda (n counter)
(cond
((> n 999) counter)
((or (= (remainder n 3) 0) (= (remainder n 5) 0))
(total (+ n 1) (+ n counter)))
(else (total (+ n 1) counter)))))


(display (total 3 0))

Conclusion
It was very simple to figure out the solution for this problem, but the point here for me is to exercise my programming skills with a series of problems. Feel free to send me your suggestions in the comments, especially about Erlang and Scheme, where I'm still new, and I need to improve.

November 10, 2008

The mind map book review

I became more interested about mind maps after reading pragmatic thinking and learning, so i went to amazon to find a good book about mind mapping. I had enough luck to find The Mind Map Book: How to Use Radiant Thinking to Maximize Your Brain's Untapped Potential, which is written directly by Tony Buzan, the creator of modern mind maps techniques.

The book is divided in three major parts, the first part explain why the use of mind maps is efficient and how it reflect the structure of our mind in the act of learning and thinking. The second part introduces the effective way of producing a mind map, explaining the difference between various techniques and methods. The last part of the book explores different environments like family, work and learning where the use of mind mapping could dramatically improve the experience.

Conclusion: be sure to read this book as soon as possible if you haven't already, even if you think that you are not interested in map mapping.

November 03, 2008

High performance web sites book review

This is a book about fast web sites.

Steve Souders, the author, was involved in the performance revision for yahoo, and collected his experience in the book high performance web sites.

The first important lesson, is that the 80-90 percent of loading time, is not time about html rendering (back-end), but instead is devoted at browser things, such as loading images, scripts and other factors that you will learn in the course of the book, which in fact is written with the purpose of reducing that amount of time.

High performance web sites  is written in a concise way, meaning that you'll find exactly the informations you need, collected in 14 easy to follow rules, most of them directly applicable for every web site.

A personal note: even if the book is oriented at front end developers, i found the chapters about conditional tags and http headers to be very interesting for the rest of us, since rails 2.2 will introduce custom helpers for take advantage of them.

October 26, 2008

The millionaire next door book review

The millionaire next door is a book written by Thomas J. Stanley and William D. Danko that is the result of many years of research about the lifestyle of the millionaires people in United States.


If you think that common millionaire individuals spend their time with shopping, buy new cars and travels, you might be wrong. Researches (included in the book) shows that the major average of millionaires don't usually buy a current-year car model, they don't spend their money in shopping or travels and much more.

Unfortunately television is bombarding our minds with images of cool people with a lot of money that enjoy life, but I now know they are not following typical lifestyle of a self-made rich person.

Of course you will learn how they becomes rich by saving money, investing instead of paying more taxes. I recommend this book to anyone that is looking for proven cases about how people accumulate fortunes or simply on how to became more wealth. 

October 20, 2008

About lambda in rails named scope

Rails 2.1 shipped with a very nice feature called named scope. If you not know what named scope are, please see this post or this screen-cast.

You will probably be aware of the use of lambda for creating dynamic finders, like this one:

named_scope :colors, lambda { |color| { :conditions => ['color = ?', color] } }

but what if you need to use a condition involving time, for instance:

named_scope :recents, :conditions => ['created_at < ?', 2.weeks.ago]

This code will not work, because named scopes are wrapped in a class method when you load the rails environment, and you will result in queries that will never change. The solution of course is the use of lambda. A lambda is a function that need to be evaluated all the times. Here's the correct example, re-written using lambda:

named_scope :recents, lambda { { :conditions => ['created_at < ?', 2.weeks.ago] } }

If you still are not convinced about this behavior, try out this code yourself:

class Foo
 attr_accessor :container
 
 def initialize
 @container = []
 end
 
end

f = Foo.new
f.container << Time.now
puts f.container[0] # => Sat Oct 18 19:51:40 -0700 2008
sleep 3;
puts f.container[0] # => Sat Oct 18 19:51:40 -0700 2008


f = Foo.new
f.container << lambda { Time.now }
puts f.container[1].call # => Sat Oct 18 19:51:43 -0700 2008
sleep 3;
puts f.container[1].call # => Sat Oct 18 19:51:46 -0700 2008

October 19, 2008

The me Meme

This is me in my hotel room in Seattle:

Photo 1

Via Obie Fernandez

1.Take a picture of yourself right now.
2. Don’t change your clothes, don’t fix your hair…just take a picture. (should be super-easy with Photobooth)
3. Post that picture with NO editing.
4 Post these instructions with your picture.

Eat that frog book review

Eat that frog is a book written by Brian Tracy that will help overcome procrastination and achieve more goals. The author describe a set of practical methods which are easy to follow but with an high potential positive impact in our life.


The book starts by explaining a set of advices on how to plan our everyday tasks, how to become more productive by overcoming procrastination and how to achieve more by doing less. This part will probably not be a revelation for you (unless you have never read about getting things done), but in the rest of the book there will be advices on how to focus into results , how to improve your key skills and maximize our power.

I highly recommend this book to anyone who is looking for time management and self improvement books and practical advices, although everyone would benefit by reading it.

October 16, 2008

Seattle.rb first impression

Yesterday I had the opportunity to go to seattle.rb, the weekly ruby brigade, where very cool guys share their knowledge about ruby and constantly work on new exciting projects.

I used that time to browse the source code of a few projects like ZenTest and to chat with someone, I plan to be there also the next week, so stay tuned.

October 14, 2008

The richest man in Babylon book review

I started to read business related books later this year, and I was lucky enough to start with a few excellent ones, including The richest man in Babylon by George S. Clason.

Clasonrichestmaninbabylon

This book was originally written in 1920 and describes the financial situation in the ancient Babylon. You may wonder how it can help us in the 21st century where so many things are changed. It eventually turns out that things aren't really that changed when we talk about making money.

The most important lesson that i learned is that you need to save a little a little part of all your incoming if you want to became rich, and when you have enough money you can start to invest them.

Aside from the business advices included, I really enjoyed reading this book. The author found the right words for telling us a beautiful story about the ancient Babylon and moneys. A must read for everyone.

My Photo

Pages

Stats