Archive for April, 2008

Week 6 Homework

Wednesday, April 30th, 2008

Here is your Week 6 homework, and the week 6 sample code.

Week 6 Slides

Wednesday, April 30th, 2008

This weeks topics are mostly requested. I’m going to try to fulfill the rest of your requests in the weeks to come! Here are the week 6 slides.

Week 5 Sample Code

Thursday, April 24th, 2008

Hey everyone, I’ve attached the week 5 examples here. Enjoy!

Your Week 5 Homework

Wednesday, April 23rd, 2008

Here is your homework for week 5. You’ll be doing some network programming, fetching a web page, writing a chat client, and working with rinda. Good luck!

This is due May 2nd.

Week 5 Slides

Wednesday, April 23rd, 2008

Hey everyone. Here are your week 5 slides.

Tonight we’ll be discussing network programming, as well as distributed ruby. I’ll also have my airport express in class for people to play with.

Week 4 Extra Credit Test

Thursday, April 17th, 2008

Hey everyone! If you’d like to do the extra credit problem, here is a test that you can use to benchmark your solution:

  require 'digest/md5'
  require 'test/unit'
  def test_encode_alac_speed
    in_filename = 'test/data/3db65f4f0e1b01a3307c3c2c2ddedbb7.wav'
    out_filename = 'test/data/out.raw'
    assert_equal('3db65f4f0e1b01a3307c3c2c2ddedbb7',
      Digest::MD5.hexdigest(File.read(in_filename))
    )
    File.open(in_filename, 'rb') { |file|
      File.open(out_filename, 'wb') { |outf|
        while data = file.read(4096 * 2 * 2)
          outf.write(Week4.encode_alac(data))
        end
      }
    }
    assert_equal('62047625a959a52469e81a90d852329e',
                 Digest::MD5.hexdigest(File.read(out_filename)))
  end

You’ll need to drop this file in to the test/data directory. But watch out, the file is 29MB. It took about 64 seconds to process on my machine. The extra credit is to make the encode_alac method faster, and to make the method work with Ruby 1.9. There will be a prize for the fastest implementation as well as a prize for a Ruby 1.9 implementation.

I will also come up with a solution and throw it in to the mix. Good luck, and have fun!

Week 4 Slides and Homework

Wednesday, April 16th, 2008

Here are the Week 4 slides along with the Week 4 Homework.

The third test is extra credit!

Week 3 Homework Update

Monday, April 14th, 2008

Garrick found a problem with the Week 3 homework and posted in the comments for week 3. In the week 3 homework, test_add_to_metaclass should be this:

  def test_add_to_the_metaclass
    phil  = Week3::Album.new(phil_collins)
    assert !phil.singleton_methods.include?("awesome?")

    # Add the singleton here!

    assert phil.singleton_methods.include?("awesome?")
    assert_equal(true, phil.awesome?)
  end

Ruby 1.9 returns a list of symbols when you call singleton_methods, but ruby 1.8 returns a list of strings. Since we’re working with Ruby 1.8, you’ll need to update your test case to get everything working.

Gem Packaging and Manifest.txt

Friday, April 11th, 2008

You may have noticed that when you tried to package your week 2 gem, you get this error:

[][aaron@amac Week_2]$ rake package
(in /Users/aaron/Desktop/Week_2)
rake aborted!
Don't know how to build task 'bin/week_2'

(See full trace by running task with --trace)
[][aaron@amac Week_2]$
  

When building your gem, Hoe looks at all of the files listed in your Manifest.txt file before packaging the gem. If there are discrepancies between the list in your Manifest.txt and the actual files in your project, Hoe will complain. In this case, there is a file listed in your Manifest.txt that has been removed. That file is ‘bin/week_2′. If you remove that entry from Manifest.txt, your gem should build.

How do I know that ‘bin/week_2′ has been removed? Well, I removed it from the package before I zipped up the project! But lets say I hadn’t told you that, and you want to know what should be in Manifest.txt. Hoe comes with a task called ‘check_manifest’ that checks your manifest, and tells you what needs to be fixed. Lets try out the task with the Week 2 homework:

[][aaron@amac Week_2]$ rake check_manifest
(in /Users/aaron/Desktop/Week_2)
--- Manifest.txt	2008-04-08 22:11:47.000000000 -0700
+++ Manifest.tmp	2008-04-11 10:34:31.000000000 -0700
@@ -2,6 +2,5 @@
 Manifest.txt
 README.txt
 Rakefile
-bin/week_2
 lib/week_2.rb
-test/test_week_2.rb
\ No newline at end of file
+test/test_week_2.rb
[][aaron@amac Week_2]$

That task spit out a diff file that tells us how to change the Manifest. It says we need to remove ‘bin/week_2′ and move ‘test/test_week_2.rb’ to the bottom of the file. If you have the ‘patch’ command on your system, you can use the output of this command to fix your Manifest.txt:

[][aaron@amac Week_2]$ rake check_manifest | patch -p0
patching file Manifest.txt
[][aaron@amac Week_2]$

Now when we run the ‘check_manifest’ task, no diff file is produced because our Manifest file is properly updated:

[][aaron@amac Week_2]$ rake check_manifest
(in /Users/aaron/Desktop/Week_2)
[][aaron@amac Week_2]$

Also our gem packaging works now!

[][aaron@amac Week_2]$ rake package
(in /Users/aaron/Desktop/Week_2)
tar zcvf Week2-1.0.0.tgz Week2-1.0.0
Week2-1.0.0/
Week2-1.0.0/History.txt
Week2-1.0.0/Manifest.txt
Week2-1.0.0/README.txt
Week2-1.0.0/Rakefile
Week2-1.0.0/lib/
Week2-1.0.0/lib/week_2.rb
Week2-1.0.0/test/
Week2-1.0.0/test/test_week_2.rb
  Successfully built RubyGem
  Name: Week2
  Version: 1.0.0
  File: Week2-1.0.0.gem
[][aaron@amac Week_2]$

Before you make a gem release, it is always important to make sure that your Manifest file is up to date. Always run check_manifest, look over the changes it wants to make, and apply the correct changes before packaging.

Week 3 Slides

Wednesday, April 9th, 2008

Here are the week 3 slides that we’ll be reviewing tonight.

Here is the Week 3 Homework.

Tonight we’ll review the week 3 slides, and work on the week 2 homework in class. I’m making the week 3 homework due on Friday April 18th.