Archive for the ‘Homework’ Category

Week 5 Homework

Wednesday, May 6th, 2009

2 HTTP Servers (really basic HTTP 0.9/GET only):

  • gserver for thread spawning per connection
  • tcpserver w/ prespawned thread pool

requirements:

  • craft your own request / response objects
  • servelets of your own design. start with time of the day app.
  • static files from the filesystem.
  • html files served plain
  • html.erb files should render via erb.
  • no caching, no clever.

Bare minimum HTTP protocol:

  • request:

GET /index.html HTTP/1.0 CRLF
CRLF

  • response:

HTTP/1.1 200 OK CRLF
Date: Thu, 07 May 2009 01:06:01 GMT CRLF
Last-Modified: Mon, 19 Jan 2009 23:02:19 GMT CRLF
Content-Length: 3750 CRLF
Content-Type: text/html CRLF
CRLF
...content...

  • other responses are:
  • 304 redirected
  • 404 missing
  • 500 app error

2 Chat Servers:

drb-based centralized chat server & client

  • port 31337
  • multiple users, nick
  • multiple channels
  • join/leave
  • no protocol otherwise
  • client does no authentication, just connects.
  • server announces connection, etc.
  • protocol is objects, not text.

multicast plaintext chat server/client (distributed `wall`)

  • port 7387
  • broadcast text to others.
  • print all text you see.
  • zero protocol

General Requirements:

  • must be TDD. start with direct objects, no network.
  • check your manifest before you package or I’ll dock you w/o mercy.

HELLO! HERE IS YOUR WEEK 4 HOMEWORK

Wednesday, April 29th, 2009

Your week four homework is two parts. The first part is making your week 3 homework use threads. Make the tasks in your week 3 homework run in parallel. Make sure to synchronize when appropriate.

The second part is writing an apache log processor. For this project you will:

  • Provide a commandline tool that safely modifies files
  • Change IP Address at the beginning of the line in an Apache logfile
  • Must be multithreaded
  • Must maintain log order
  • Cache name lookups across invocations
  • Age the cache items (expire lookups)
  • Commandline option to limit number of threads (you should determine a sensible default)
  • Look at “resolv” for DNS lookups
  • This homework can be completed using only tools from ruby’s standard library

The file format will look like this:

208.77.188.166 - - [29/Apr/2009:16:07:38 -0700] "GET / HTTP/1.1" 200 1342
75.119.201.189 - - [29/Apr/2009:16:07:44 -0700] "GET /favicon.ico HTTP/1.1" 200 1406
75.146.57.34 - - [29/Apr/2009:16:08:38 -0700] "GET / HTTP/1.1" 304 -
75.119.201.189 - - [29/Apr/2009:16:09:53 -0700] "GET / HTTP/1.1" 200 1340
208.77.188.166 - - [29/Apr/2009:16:11:51 -0700] "GET / HTTP/1.1" 304 -
75.146.57.34 - - [29/Apr/2009:16:12:00 -0700] "GET / HTTP/1.1" 304 -
75.119.201.189 - - [29/Apr/2009:16:13:15 -0700] "GET / HTTP/1.1" 304 -
208.77.188.166 - - [29/Apr/2009:16:13:15 -0700] "GET / HTTP/1.1" 304 -
75.119.201.189 - - [29/Apr/2009:16:13:17 -0700] "GET / HTTP/1.1" 304 -
75.146.57.34 - - [29/Apr/2009:16:13:50 -0700] "GET / HTTP/1.1" 200 1294
75.146.57.34 - - [29/Apr/2009:16:13:55 -0700] "GET /stylesheets/main.css?1240264242 HTTP/1.1" 200 2968
74.125.67.100 - - [29/Apr/2009:16:13:55 -0700] "GET /stylesheets/home.css?1240264242 HTTP/1.1" 200 7829

We want the file to end up looking like this:

example.com - - [29/Apr/2009:16:07:38 -0700] "GET / HTTP/1.1" 200 1342
example.com - - [29/Apr/2009:16:07:44 -0700] "GET /favicon.ico HTTP/1.1" 200 1406
example.com - - [29/Apr/2009:16:08:38 -0700] "GET / HTTP/1.1" 304 -
example.com - - [29/Apr/2009:16:09:53 -0700] "GET / HTTP/1.1" 200 1340
example.com - - [29/Apr/2009:16:11:51 -0700] "GET / HTTP/1.1" 304 -
example.com - - [29/Apr/2009:16:12:00 -0700] "GET / HTTP/1.1" 304 -
example.com - - [29/Apr/2009:16:13:15 -0700] "GET / HTTP/1.1" 304 -
example.com - - [29/Apr/2009:16:13:15 -0700] "GET / HTTP/1.1" 304 -
example.com - - [29/Apr/2009:16:13:17 -0700] "GET / HTTP/1.1" 304 -
example.com - - [29/Apr/2009:16:13:50 -0700] "GET / HTTP/1.1" 200 1294
example.com - - [29/Apr/2009:16:13:55 -0700] "GET /stylesheets/main.css?1240264242 HTTP/1.1" 200 2968
example.com - - [29/Apr/2009:16:13:55 -0700] "GET /stylesheets/home.css?1240264242 HTTP/1.1" 200 7829

These domain names aren’t correct, but your output format should be similar.

Here is an example session using the command line tool you will write for your homework:

$ apache_lookup my_logs.log

After execution you should be able to examine my_logs.log and see that the ip addresses have been replaced with domain names. You should also be able to do this:

$ apache_lookup -t 100 my_logs.log
The above execution should spawn 100 threads to process your logfile.

This homework MUST be test driven. We will dock points for non-test driven code. You MUST turn your homework in as a tar.gz or as a gem. Remember to email the mailing list, use IRC, start early, test all the time, and have fun!

Week 6 Homework

Wednesday, February 18th, 2009

This week I’m having you all start a new project called “rubyholic”. Rubyholic is a website for people to find their local ruby groups. For now we’ll have two models, one called “group” to represent our ruby group, and “location” to represent the location where the group meets.

For example, the Seattle.RB group meets at Vivace, so there will be a group record with the name “Seattle.RB” and a location named “Vivace”. Locations also have latitude and longitude attributes which we’ll be using later for maps.

I want you to:

  • Create the rubyholic rails project
  • Create your models, controllers, and views
  • Limit the number of groups that are displayed to 10
  • Let the user sort groups by name
  • Let the user sort groups by location name
  • Tests! You must test all of this functionality

Before you check this project in to git, add a .gitignore file. Put this in the .gitignore file: db/.sqlite3 ..swp tags log/*.log log

Remember, turn in early and often. If you have more questions, email the list, or me, or come to my office hours every Tuesday night.

Week 2 Homework Requirements

Sunday, January 25th, 2009

Hi everyone! I mentioned this in class and in the slides, but I’m going to post it on the blog again just in case.

In addition to getting my test cases to pass, I want to see more test cases. More tests in the units, and more in the functionals. Specifically in the functionals, I want to see tests which submit form data which would be considered invalid by the models and verifies that the user is notified of their mistakes.

Remember. Turn your homework in early and often! Week 2 homework is due on the 31st at midnight.

Week 6 Homework

Wednesday, April 30th, 2008

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

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 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.