Monday, July 10, 2006

I've lost 100 pounds in 8 1/2 months

As of this morning I've officially lost 100 pounds in 8 1/2 months.

But another PhysicsDiet.com beat me to the 100 pound mark by several months. jm3000 lost 100 pounds in about 4 1/2 months.

I don't have a final goal weight in mind so I'm not sure what my next major weight milestone will be. I will probably drop below 200 pounds before I'm done. But for now I'm focused on getting my Body Fat below 15%. Once I do that I'll reevaluate where I am then I'll decide if I want to shoot for 10% Body Fat.

Lately I haven't been tracking the calories I'm consuming or the calories I'm burning from exercise. I've been using a combination of portion counting and weighing some foods. But I don't track the details anymore.

I spent several months doing different experiments trying to figure out whether I could optimize my diet by eating different ratios of macronutrients or varying the types of foods I ate. But in the end I found that it mostly doesn't matter what I eat as long as prefer healthier foods over non-healthy foods and control my calorie balance.

The key factors for me are:

  • Eat 5-6 small meals a day
    This is a critical component of my success. At first I didn't think it mattered. But when I experimented with some of the ideas from Body for Life I learned that eating 6 small meals a day is the best way to control my appetite and my emotions. I'm much more even tempered now. And I'm never hungry now as long as I eat at least 1500 calories per day. I usually eat around 2000 calories per day though.
  • Regular vigorous exercise
    For a long time I thought eating 6 small meals a day was the key to my improved mood. But recently I went about 2 weeks without doing much exercise. I've been under a lot of stress recently and I got a bit depressed. After one particularly bad weekend I jumped on my stationary bike for an hour. That's when I realized that I have to exercise to be happy. Without exercise I get much more stressed and I let little things bother me much more than they should. Exercise is the best way for me to deal with stress and relax. Exercise also helps me lose weight, but not as much as you'd think. Controlling your calorie intake is much more important if your goal is to lose weight. But exercise is critical to your health. You can't be healthy without exercise even if you control your weight. And now I know that I can't be happy without exercise.

If you're curious you can read more about my journey over on my PhysicsDiet.com Blog.

7/10/2006 7:40:44 AM (Central Standard Time, UTC-06:00)  #    Trackback

 Sunday, July 09, 2006

David Heinemeier Hansson RailsConf 2006 Keynote is now online

Well it took longer than a few minutes, but DHH's keynote is now online.

7/9/2006 8:49:16 PM (Central Standard Time, UTC-06:00)  #    Trackback

Get started with Ruby on Rails in less than 5 minutes

I first started looking at Ruby on Rails more than a year ago. I even bought the first edition of Agile Web Development with Rails as soon as it was released. But I didn't do much with Rails until recently. I didn't want to struggle with setting up Ruby, Rails, Apache, and MySQL. I've installed Apache and MySQL on Windows before and it wasn't much fun.

But now you don't have to worry about installing anything to try Rails. InstantRails includes everything you need to set up a fully working Ruby on Rails environment. Better yet, with InstantRails you don't have to install anything. You just unzip InstantRails to a folder and you have everything you need to try Ruby on Rails. If you decide you want to get rid of it just delete the InstantRails folder and your machine is back to normal.

I think this is such a big deal for Windows developers that I created a screencast showing how you can get a new Ruby on Rails application running on Windows in under 5 minutes.

5 minutes to Ruby on Rails nirvana

A flash version will eventually be available here.

7/9/2006 10:39:40 AM (Central Standard Time, UTC-06:00)  #    Trackback

 Friday, July 07, 2006

I wish I could make it to Robert Scoble's OffTheGrid campout

I was in the Emigrant Montana area last year. I took a few pictures while I was there.

A room with a view

I stayed just a few miles from the Chico Hot Springs. That was the view I woke up to every morning. If you get a chance you should definitely attend the OffTheGrid campout.

7/7/2006 8:50:05 PM (Central Standard Time, UTC-06:00)  #    Trackback

Why would Yahoo support an open source version of the Google File System?

Yahoo is supporting the development of Hadoop! Hadoop! is an open source project that is working to create a Distributed File System (think Google File System) and an implementation of MapReduce.

I find this effort by Yahoo! to be rather interesting given that platform pieces like GFS, BigTable, MapReduce and Sawzall give Google quite the edge in building mega-scale services and in Greg Linden's words are 'major force multipliers' that enable them to pump out new online services at a rapid pace. I'd expect Google's competitors to build similar systems and keep them close to their chest not give them away. I suspect that the reason Yahoo! is going this route is that they don't have enough folks to build this in-house and have thus collaborated with Hadoop project to get some help. This could potentially backfire since there is nothing stopping small or large competitors from reusing their efforts especially if it uses a traditional Open Source license. [Dare Obasanjo]

Dare is surprised that Yahoo! is working on open source versions of tools that could give them a competitive advantage. I can't tell if he thinks Yahoo! is making a mistake by doing this though. I suspect he does.

That is exactly why I don't trust Microsoft as a platform vendor. If one of Dare's ideas gives MSN a competitive advantage what do you think the odds are that we'll see that idea rolled in to the .NET Framework? I think the odds are close to 0.

There is nothing wrong with that. That doesn't make Dare a bad guy and it doesn't make Microsoft evil. But it does make Microsoft a poor choice as a platform vendor. I'm tired of waiting years to get access to Microsoft's second hand, second best ideas.

So why would Yahoo! do this? Why would they create open source versions of tools that could give them a short-term competitive advantage? I think Joel Spolsky said it best:

Smart companies try to commoditize their products' complements. [Joel Spolsky]

Yahoo! is not in the business of selling software. They sell advertising. Software is one of their biggest complements. The best way to commoditize software is to open source it.

Google could probably gain some competitive advantage by developing their own operating system. But they don't. I wonder why.

7/7/2006 1:37:22 PM (Central Standard Time, UTC-06:00)  #    Trackback

 Thursday, July 06, 2006

Rails doesn't need "Enterprise" features

Dave Thomas asked the Rails community to add "Enterprise" features during his RailsConf 2006 keynote.

I had been disheartened earlier in the day by Dave Thomas's talk (no offense, Dave!) Dave's a great guy and has been great to the Ruby community. And although I agreed with some of what Dave said, I couldn't have disagreed more with his view on changing Rails to play better in legacy environments. I sure was relieved to hear DHH's talk the following night. But I still recommend that you view his keynote, too: see what you think and let us know your thoughts. [Softies On Rails]

I agree with Jeff from Softies On Rails. I respect Dave Thomas a lot, but I did not care for the message he brought to RailsConf. At times his keynote was quite condescending. I don't think Dave meant it that way, but all his talk of "in the real world" probably wasn't received well by the RailsConf audience.

I work in the "real world" that Dave was talking about. It sucks! I can't wait to get out. Rails is a breath of fresh air precisely because it doesn't target the "enterprise". It was built by an agile team to create new agile web applications. If you need to create a new agile web application then Rails is a perfect match. But if you need to create yet another big upfront designed enterprise monstrosity, Rails is probably not going to work for you.

Dave also talked about improving the deployment of Rails applications. This is more applicable to the general Rails community. But I disagree with his idea that developers shouldn't be worried about how the application is going to run. That is a mistake. It sounds good in theory, but it ends up creating a situation where the developers make decisions that make the system almost impossible to maintain in production. For small teams you are much better off requiring the developers to own the entire system. If possible they should be responsible for testing, customer support, operations, design and development. As soon as you relieve them of responsibility in any of these areas you can guarantee they are going to make decisions that make it more difficult to support the application in that area.

I'm glad that the core team is focused on solving their problems not some enterprise's problems. Because their problems are my problems. It is strange to work with a platform that is built by people who actually use the platform to build real applications. I've spent so many years depending on platforms that Microsoft creates but doesn't actually use that I didn't realize how much I was missing.

Like Jeff said, watch Dave's keynote and let us know what you think. I am looking forward to seeing DHH's keynote.

7/6/2006 8:51:51 PM (Central Standard Time, UTC-06:00)  #    Trackback

 Wednesday, July 05, 2006

David Heinemeier Hansson's RailsConf 2006 Keynote should be available any minute now

I almost missed this. The Keynotes from RailsConf 2006 are being published on ScribeMedia's site. DHH's Keynote was scheduled for release today so it should be available any time now. In the mean time you can see Dave Thomas' and Martin Fowler's keynotes.

7/5/2006 9:42:11 PM (Central Standard Time, UTC-06:00)  #    Trackback

 Saturday, June 24, 2006

Congratulations Les Orchard and good luck Joe Gregorio

Les Orchard just got a new job at Yahoo. He sounds completely psyched. He deserves it. I can't wait to hear what new and exciting stuff he ends up doing.

Joe Gregorio is looking for a new gig. If you are looking for a creative, passionate developer you should check out Joe's resume.

I've never met Les or Joe. But I feel like I know them both after following their online adventures for almost 5 years. Hell I even have a DECAFBAD T-Shirt.

Unfortunately now I won't get a chance to meet Les. My family lives in Ann Arbor and I've always planned on giving Les a call the next time I'm in his neck of the woods. I guess now I'll have to go out to San Francisco to meet him.

Les & Joe are both great guys and they deserve the best this life has to offer. Good luck guys!

6/24/2006 9:17:25 PM (Central Standard Time, UTC-06:00)  #    Trackback

 Wednesday, June 21, 2006

Dates loaded from the database are not valid when using validates_date_time with us_date_format

I spent quite a while trying to track down a problem in the Rails validates_date_time plugin. In the end the fix was simple, but since I'm new to Rails and Ruby I assumed I was doing something wrong. I finally decided to dig into the code and tests for validates_date_time to see if I could find a bug.

The Problem: I have a model called Person. The schema looks like so:


ActiveRecord::Schema.define(:version => 1) do

create_table "people", :force => true do |t|
	t.column "name", :string
	t.column "date_of_birth", :datetime
end

end

I set ActiveRecord::Validations::DateTime.us_date_format = true.

I can create a new Person just fine like so:


ruby script/console
>> require 'pp'
=> true
>> p = Person.create(:name => "Test", :date_of_birth => Date.new(1972, 12, 31))
>> p.valid?
=> true

Great. But when I try to load the person from the database there is a problem.


>> p = Person.find_by_name("Test")
=> #"Test", "id"=>"2", "date_of_birth"=>"
1972-12-31"}>
>> p.valid?
=> false
>> p.errors.on(:date_of_birth)
=> "is an invalid date"

What happens if I set ActiveRecord::Validations::DateTime.us_date_format = false? Let's see.


>> ActiveRecord::Validations::DateTime.us_date_format = false
=> false
>> p = Person.find_by_name("Test")
=> #"Test", "id"=>"2", "date_of_birth"=>"
1972-12-31"}>
>> p.valid?
=> true

The problem seems to be related to the use of us_date_format. So what is going on?

The validate_date_time plugin looks at each attribute that is passed to validates_date and looks at the *_before_type_cast version of the attribute. In our case it is looking at p.date_of_birth_before_type_cast. Here's what it sees:


>> ActiveRecord::Validations::DateTime.us_date_format = true
=> true
>> p = Person.find_by_name("Test")
=> #"Test", "id"=>"2", "date_of_birth"=>"
1972-12-31"}>
>> p.date_of_birth_before_type_cast
=> "1972-12-31"

So our raw value of our date_of_birth is "1972-12-31". That looks perfectly reasonable since it is an ISO date and ISO dates are the best way to represent dates since they are easily parsed. So why is that date considered invalid?

The validate_date_time plugin uses a parse_date method to parse date values. Here's what it looks like:


def parse_date(value)
	raise if value.blank?
	return value if value.is_a?(Date)
	return value.to_date if value.is_a?(Time)
	raise unless value.is_a?(String)
	
	year, month, day = case value.strip
		# 22/1/06 or 22\1\06
		when /^(\d{1,2})[\\\/\.:-](\d{1,2})[\\\/\.:-](\d{2}|\d{4})$/ then [$3, $2, $1]
		# 22 Feb 06 or 1 jun 2001
		when /^(\d{1,2}) (\w{3,9}) (\d{2}|\d{4})$/ then [$3, $2, $1]
		# July 1 2005
		when /^(\w{3,9} (\d{1,2}) (\d{2}|\d{4}))$/ then [$3, $1, $2]
		# 2006-01-01
		when /^(\d{4})-(\d{2})-(\d{2})$/ then [$1, $2, $3]
		# Not a valid date string
		else raise
	end
	
	month, day = day, month if ActiveRecord::Validations::DateTime.us_date_format
	
	Date.new(unambiguous_year(year), month_index(month), day.to_i)
rescue
	raise DateParseError
end

The last when statement is where our ISO date of "1972-12-31" matches. At that point year = "1972", month = "12", and day = "31". But then if us_date_format is true, the value of month and day get swapped. Now year = "1972", month = "31", and day = "12".

But that can't be right. The unit tests for validates_date_time all run clean and the date_test.rb has test cases for us_date_format. So what gives?

Here are the tests to prove it:


def test_us_date_format
	with_us_date_format do
		{'1/31/06'  => '2006-01-31', '2\28\01'  => '2001-02-28',
		'10/10/80' => '1980-10-10', '7\4\1960' => '1960-07-04'}.each do |value, result|
			assert_update_and_equal result, :date_of_birth => value
		end
	end
end

Running the Plugin tests (after configuring a database for the validates_date_time plugin to use) results in this:


c:> rake test:plugins
Started
.....................
Finished in 0.703 seconds.

21 tests, 121 assertions, 0 failures, 0 errors

The problem is that the test_us_date_format is not testing a date like ours. Let's change it to look like this:


def test_us_date_format
	with_us_date_format do
		{'1/31/06'  => '2006-01-31', '2\28\01'  => '2001-02-28',
		'10/10/80' => '1980-10-10', '7\4\1960' => '1960-07-04',
		'1972-12-31' => '1972-12-31'}.each do |value, result|
			assert_update_and_equal result, :date_of_birth => value
		end
	end
end

That says, when use_date_format is true I expect to receive the same value when I update a date_of_birth field with an ISO formatted date of '1972-12-31'. What happens when we run the tests now:


c:> rake test:plugins
Started
........F..F.........
Finished in 0.75 seconds.

1) Failure:
test_us_date_format(DateTest)
	[./vendor/plugins/validates_date_time/test/abstract_unit.rb:44:in `assert_up
date_and_equal'
	./vendor/plugins/validates_date_time/test/date_test.rb:70:in `test_us_date_
format'
	./vendor/plugins/validates_date_time/test/date_test.rb:69:in `test_us_date_
format'
	./vendor/plugins/validates_date_time/test/abstract_unit.rb:65:in `with_us_d
ate_format'
	./vendor/plugins/validates_date_time/test/date_test.rb:66:in `test_us_date_
format']:
{:date_of_birth=>"1972-12-31"} should be valid.
 is not true.

2) Failure:
test_various_formats(DateTimeTest)
	[./vendor/plugins/validates_date_time/test/abstract_unit.rb:50:in `assert_up
date_and_match'
	./vendor/plugins/validates_date_time/test/date_time_test.rb:12:in `test_var
ious_formats'
	./vendor/plugins/validates_date_time/test/date_time_test.rb:11:in `test_var
ious_formats']:
<"Tue Jan 03 19:00:00 Central Standard Time 2006"> expected to be =~
.

21 tests, 114 assertions, 2 failures, 0 errors
rake aborted!
Command failed with status (1): [c:/ruby/bin/ruby -Ilib;test "c:/ruby/lib/r...]

(See full trace by running task with --trace)

The first failure is the one we're interested in. It demonstrates the problem we're seeing. Let's see if we can fix it.

Replace the parse_date method in validates_date_time.rb with this:


def parse_date(value)
	raise if value.blank?
	return value if value.is_a?(Date)
	return value.to_date if value.is_a?(Time)
	raise unless value.is_a?(String)
	
	year, month, day, is_iso = case value.strip
		# 22/1/06 or 22\1\06
		when /^(\d{1,2})[\\\/\.:-](\d{1,2})[\\\/\.:-](\d{2}|\d{4})$/ then [$3, $2, $1]
		# 22 Feb 06 or 1 jun 2001
		when /^(\d{1,2}) (\w{3,9}) (\d{2}|\d{4})$/ then [$3, $2, $1]
		# July 1 2005
		when /^(\w{3,9} (\d{1,2}) (\d{2}|\d{4}))$/ then [$3, $1, $2]
		# 2006-01-01
		when /^(\d{4})-(\d{2})-(\d{2})$/ then [$1, $2, $3, true]
		# Not a valid date string
		else raise
	end
	
	month, day = day, month if !is_iso && ActiveRecord::Validations::DateTime.us_date_format
	
	Date.new(unambiguous_year(year), month_index(month), day.to_i)
rescue
	raise DateParseError
end

Now we're setting a local variable is_iso to true when our date matches the ISO formatted when statement. Now when is_iso is true we can skip the swapping of the month and day values. Let's run some tests and see if this is working:


c:> rake test:plugins
Started
.....................
Finished in 0.688 seconds.

21 tests, 123 assertions, 0 failures, 0 errors

Perfect. Now everything should be working in the console too. Let's check:


>> ActiveRecord::Validations::DateTime.us_date_format = true
=> true
>> p = Person.find_by_name("Test")
=> #"Test", "id"=>"2", "date_of_birth"=>"
1972-12-31"}>
>> p.valid?
=> true

Looks good. I think that should do it. I wonder if this explains why the validates_date_time plugin is only rated 3 out of 5 stars here. It is a great plugin, it just looks like the us_date_format might be a little rough around the edges.

6/21/2006 9:28:16 AM (Central Standard Time, UTC-06:00)  #    Trackback

 Tuesday, June 20, 2006

Using In Memory Database for RubyCLR Tests

Even better than just using a SQLite database like I talked about yesterday, I'd love to use a SQLite 3 in memory database for the RubyCLR tests.

6/20/2006 8:53:46 AM (Central Standard Time, UTC-06:00)  #    Trackback


Links

Categories

Archives