Categories
Uncategorized

My Stack of Old Computer Books

While cleaning out my home office, I found a box books that I’ve been hanging on to for historical purposes and sentimental reasons.

First, this collection of Apple ][ manuals, back from when I had my first computer, an Apple //e. These manuals came with the original apple ][; my //e manuals must be kicking around somewhere…

Apple ][ Manuals

And from my university days, these books: the Adele Goldberg Smalltalk-80 series, Computer Systems in Business, which is rather quaint when read with today’s eyes, and Inside Macintosh from the System 7/8 era:

Smalltalk-80 books, "Computer Systems in Business", Inside Macintosh books

I know I’ve got Lubomir Bic’s The Logical Design of Operating Systems — from which I learned concurrent programming — stashed away, but I can’t seem to find it at the moment.

Categories
Uncategorized

Pics from the Office

I was inspired by yesterday’s posting of the office space used by people developing the Boeing 787 Dreamliner to post photos of b5media’s tech team office. This is the old b5media office; the rest of the team — operations, content, marketing and advertising — are in an office across the hall.

The space is looking pretty zen right now, but I kind of like it. We’ll fill it up eventually.

You can click any of the thumbnails below to see the full-size photo:

Categories
Uncategorized

Enumerating Enumerable: Enumerable#first

Enumerating Enumerable

Welcome to another installment of Enumerating Enumerable, my series of articles in I attempt to do a better job of documenting Ruby’s Enumerable module than Ruby-Doc.org. In this installment, I cover the first method.

In case you missed any of the previous articles, they’re listed and linked below:

  1. all?
  2. any?
  3. collect / map
  4. count
  5. cycle
  6. detect / find
  7. drop
  8. drop_while
  9. each_cons
  10. each_slice
  11. each_with_index
  12. entries / to_a
  13. find_all / select
  14. find_index

Enumerable#first Quick Summary

Graphic representing the "first" method in Ruby's "Enumerable" module

In the simplest possible terms What are the first n items in the collection?
Ruby version 1.8 and 1.9
Expects An optional integer n that specifies the first n items of the collection to return. If this integer is not given, n is 1 by default.
Returns If first is applied to a collection containing m elements:

  • The first item in the collection, if m > 0 and no argument n is provided.
  • An array containing the first n items in the collection, if m > 0 and an argument n is provided.
  • nil if the collection is empty and no argument n is provided.
  • The empty array [] if the collection is empty and an argument n is provided.
RubyDoc.org’s entry Enumerable#first

Enumerable#first and Arrays

When used on an array without an argument, first returns the first item in the array:

posts = ["First post!", "Second post!", "Third post!"]
=> ["First post!", "Second post!", "Third post!"]

# What's the first item in posts?
posts.first
=> "First post!"

# Here's the equivalent using array notation:
posts[0]
=> "First post!"

When used on an array with an integer argument n, first returns an array containing the first n items in the original array:

# What are the first 2 items in posts?
posts.first 2
=> ["First post!", "Second post!"]

# Note that when you provide an argument of 1,
# the result is still an array -- with just one element.
# If you want a scalar, don't use an argument.
posts.first 1
=> ["First post!"]

# Here's the equivalent using array slice notation:
posts[0..1]
=> ["First post!", "Second post!"]

posts[0...2]
=> ["First post!", "Second post!"]

When used on an empty array, first returns:

  • nil if no argument n is provided
  • The empty array, [], if an argument n is provided

[].first
=> nil

[].first 2
=> []

Enumerable#first and Hashes

In Ruby 1.8 and previous versions, hash order is seemingly arbitrary. Starting with Ruby 1.9, hashes retain the order in which they were defined, which makes the first method a little more applicable.

When used on a hash without an argument, first returns the first item in the hash as a two-element array, with the key as the first element and the corresponding value as the second element.

# Let's see what stages of partying our friends are in
party_stages = {"Alice" => :party_mineral,
                "Bob"   => :party_animal,
                "Carol" => :party_reptile,
                "Dave"  => :party_vegetable}
=> {"Alice"=>:party_mineral, "Bob"=>:party_animal, "Carol"=>:party_reptile, "Dave"=>:party_vegetable}

# Who's the first partier and what state is s/he in?
party_stages.first
=> ["Alice", :party_mineral]

When used on a hash with an integer argument n, first returns an array containing the first n items in the hash, with each item represented as a two-element array:

party_stages.first 2
=> [["Alice", :party_mineral], ["Bob", :party_animal]]

# Note that when you provide an argument of 1,
# the result is still an array -- with just one element.
# If you want a scalar, don't use an argument.
party_stages.first 1
=> [["Alice", :party_mineral]]

When used on an empty hash, first returns:

  • nil if no argument n is provided
  • The empty array, [], if an argument n is provided

{}.first
=> nil

{}.first 2
=> []

Categories
Uncategorized

Now THIS is a Cool Office!

I used to envy the office space that local Ruby heroes Unspace have (they’re just down the street from b5), but now I envy the office space used by the people working on the Boeing 787 Dreamliner:

Boeing 787 under construction
Click to see a larger version.
Photo courtesy of Miss Fipi Lele.

Categories
Uncategorized

Enumerating Enumerable: Enumerable#find_index

Enumerating Enumerable

Once again, it’s Enumerating Enumerable, my series of articles in which I attempt to outdo Ruby-Doc.org’s documentation of Ruby’s Enumerable module. In this article, I cover the find_index method, which was introduced in Ruby 1.9.

In case you missed any of the previous articles, they’re listed and linked below:

  1. all?
  2. any?
  3. collect / map
  4. count
  5. cycle
  6. detect / find
  7. drop
  8. drop_while
  9. each_cons
  10. each_slice
  11. each_with_index
  12. entries / to_a
  13. find_all / select

Enumerable#find_index Quick Summary

Graphic representation of the "find_index" method in Ruby's "Enumerable" module

In the simplest possible terms What’s the index of the first item in the collection that meets the given criteria?
Ruby version 1.9
Expects A block containing the criteria.
Returns
  • The index of the item in the collection that matches the criteria, if there is one.
  • nil, if no item in the collection matches the crtieria.
RubyDoc.org’s entry Enumerable#find_index

Enumerable#find_index and Arrays

When used on an array, find_index passes each item in the array to the given block and either:

  • Stops when the current item causes the block to return a value that evaluates to true (that is, anything that isn’t false or nil) and returns the index of that item, or
  • Returns nil if there is no item in the array that causes the block to return a value that evaluates to true.

Some examples:

# How about an array of the name of the first cosmonauts and astronauts,
# listed in the chronological order of the missions?
mission_leaders = ["Gagarin", "Shepard", "Grissom", "Titov", "Glenn", "Carpenter",
"Nikolayev", "Popovich"]
=> ["Gagarin", "Shepard", "Grissom", "Titov", "Glenn", "Carpenter", "Nikolayev",
"Popovich"]

# Yuri Gagarin was the first in space
mission_leaders.find_index{|leader| leader == "Gagarin"}
=> 0

# John Glenn was the fifth
mission_leaders.find_index{|leader| leader == "Glenn"}
=> 4

# And James Tiberius Kirk is not listed in the array
kirk_present = mission_leaders.find_index{|leader| leader == "Kirk"}
=> nil

Enumerable#find_index and Hashes

When used on a hash, find_index passes each key/value pair in the hash to the block, which you can “catch” as either:

  1. A two-element array, with the key as element 0 and its corresponding value as element 1, or
  2. Two separate items, with the key as the first item and its corresponding value as the second item.

As with arrays, find_index:

  • Stops when the current item causes the block to return a value that evaluates to true (that is, anything that isn’t false or nil) and returns the index of that item, or
  • Returns nil if there is no item in the array that causes the block to return a value that evaluates to true.

Some examples:

require 'date'
=> true

# These are the names of the first manned spaceships and their launch dates
launch_dates = {"Kedr"              => Date.new(1961, 4, 12),
                "Freedom 7"         => Date.new(1961, 5, 5),
                "Liberty Bell 7"    => Date.new(1961, 7, 21),
                "Orel"              => Date.new(1961, 8, 6),
                "Friendship 7"      => Date.new(1962, 2, 20),
                "Aurora 7"          => Date.new(1962, 5, 24),
                "Sokol"             => Date.new(1962, 8, 11),
                "Berkut"            => Date.new(1962, 8, 12)}
=> {"Kedr"=>#<Date: 4874803/2,0,2299161>, "Freedom 7"=>#<Date: 4874849/2,0,2299161>,
"Liberty Bell 7"=>#<Date: 4875003/2,0,2299161>, "Orel"=>#<Date: 4875035/2,0,2299161>,
"Friendship 7"=>#<Date: 4875431/2,0,2299161>, "Aurora 7"=>#<Date: 4875617/2,0,2299161>,
"Sokol"=>#<Date: 4875775/2,0,2299161>, "Berkut"=>#<Date: 4875777/2,0,2299161>}

# Where in the list is John Glenn's ship, the Friendship 7?
launch_dates.find_index{|ship, date| ship == "Friendship 7"}
=> 4

# Where in the list is the first mission launched in August 1962?
launch_dates.find_index{|ship, date| date.year == 1962 && date.month == 8}
=> 6

# The same thing, expressed a little differently
launch_dates.find_index{|launch| launch[1].year == 1962 && launch[1].month == 8}
=> 6

Using find_index as a Membership Test

Although Enumerable has a method for checking whether an item is a member of a collection (the include? method and its synonym, member?), find_index is a more powerful membership test for two reasons:

  1. include?/member? only check membership by using the == operator, while find_index lets you define a block to set up all sorts of tests. include?/member? asks “Is there an object X in the collection equal to my object Y?” while find_index can be used to ask “Is there an object X in the collection that matches these criteria?”
  2. include?/member? returns true if there is an object X in the collection that is equal to the given object Y. find_index goes one step further: not only can it be used to report the equivalent of true if there is an object X in the collection that is equal to the given object Y, it also reports its location in the collection.

A quick example of this use in action:

# Once again, the mission leaders
mission_leaders = ["Gagarin", "Shepard", "Grissom", "Titov", "Glenn", "Carpenter",
"Nikolayev", "Popovich"]
=> ["Gagarin", "Shepard", "Grissom", "Titov", "Glenn", "Carpenter", "Nikolayev",
 "Popovich"]

# Yuri Gagarin is in the list
gagarin_in_list = mission_leaders.find_index {|leader| leader == "Gagarin"}
=> 0

# Captain James T. Kirk is not
kirk_in_list = mission_leaders.find_index {|leader| leader == "Kirk"}
=> nil

# gagarin_in_list is 0, which as a non-false and non-nil value evaluates as true.
# We can use it as both a membership test *and* as his location in the list.
p "Gagarin's there. He's number #{gagarin_in_list + 1} in the list." if gagarin_in_list
"Gagarin's there. He's number 1 in the list."
=> "Gagarin's there. He's number 1 in the list."

# kirk_in_list is nil, which is one of Ruby's two "false" values.
# Let's use it with the "something OR something else" idiom that
# many Ruby programmers like.
kirk_in_list || (p "You only *think* he wasn't there.")
"You only *think* he wasn't there."
=> "You only *think* he wasn't there."

Parts that Haven’t Been Implemented Yet

Ruby-Doc.org’s documentation is generated from the comments in the C implementation of Ruby. It mentions a way of calling find_index that is just like calling include?/member?:

# What the docs say (does not work yet!)
["Alice", "Bob", "Carol"].find_index("Bob")
=> 1

# What happens with the current version of Ruby 1.9
["Alice", "Bob", "Carol"].find_index("Bob")
ArgumentError: wrong number of arguments(1 for 0)
...


Ruby 1.9 is considered to be a work in progress, so I suppose it’ll get implemented in a later release.

Categories
Uncategorized

XBox on a REALLY Big Screen

"Grand Theft Auto" on a movie screen

Here’s something for gamers who want to go big: the Cineplex chain of movie theatres in Canada is renting out downtime at 29 of its locations to people who want to play XBox 360 games on their giants screens. CDN$179 (US$169) gets you and 11 of your friends 2 hours’ worth of big screen time.

Here’s an excerpt from the CBC article:

Theatres will generally have about 12 to 24 hours of available downtime a week, mostly in the morning, she said. Many theatres are in “full grind” right now showing summer movies, but they should slow down and have more available time once school begins in September.

Theatres may also stay open late into the evening to accommodate groups, at the discretion of each manager.

“If they wanted to book a four-hour window, we could certainly go later in the evening,” [Pat Marshall, Cineplex’s vice-president of communications] said. “If the theatre manager has the staffing, they could go till two in the morning.”

The wife is a big Rock Band aficionado. Maybe I could book something for her birthday…

Categories
Uncategorized

Nine Startup Diseases and How to Cure Them

"Game Over" screen from the '80s arcade game "Battlezone"

Maybe I’m a glutton for punishment: my current job as Tech Project Manager at b5media marks the fourth startup for which I’ve worked; if you count Mackerel Interactive Multimedia — whose story, Burying the Fish, was written by Cory Doctorow for Wired but never published — I’ve worked at five. I like the “feel” of working at a startup, and now that I’ve got experience and real-world and blog-based reputations to back me up, startups are willing to pay me not only to be part of their team but to also be the “adult supervision”. At the ripe old age of 40, I’m an elder statesman in these parts (and playing an old man’s instrument only adds to that image).

That’s why I read SitePoint’s article Nine Deadly Startup Diseases—and How to Cure Them with a sense of deja vu, going through each item in their list of mistakes and saying “yup, did that one…did that one too…”

Put together, the startups for which I worked had all but one of the diseases listed in the article except for “Marketing Blind Spot”. For some reason, there was always a marketer in our midst, drumming it into our heads that marketing was necessary.

I’ve taken their list of startup diseases and cures and summarized it in the table below. For full explanations behind each disease and cure, be sure to read the article.

Startup Disease Cure
Imaginary User Syndrome: Your product isn’t targeted at anyone in particular. Establish a small, defined set of users who could benefit from your product and tailor it to them.
Frenetic Distraction Pox: Wasting time on non-essential tasks that don’t bring the business closer to break-even or profit. Focus!
Wrong Hire Infection: You’ve hired people who can’t perform or who underperform. “The smart, brave solution in those cases is amputation. Let them go gently if you want, but let them go.”
Implicit Promise Fever: You’re assuming that there are certain promises made between you and your co-founders, but you haven’t discussed them directly or put them in writing. “Have those discussions. Write the results down.”
Stealth Product Delusion: You’re waiting way too long to show your product to users while honing it to perfection (or as close to perfect as you can get). Get people to look at it! They’ll have some criticism, but that feedback is going to be very valuable.
Wrong Platform Fracture: The platform on which you’re developing (language, framework, technology) keeps getting in the way of development. Maybe you think you’ve gone too far to turn around and switch platforms. Switch platforms! ““We’ve walked this far already” isn’t a good enough reason to continue heading in that direction. Chances are, you’re much, much further from the completion of your product than you think.”
Other Interest Disorder: Other interests are pulling at you; you’re either saying “but I’m still working on my startup” and “I’ll get back to my startup soon” or working on several startups at once. Pick the project you want to work on, and break cleanly from the others.
Perfection Hallucination: You’re spending a large amount of time getting your prodcut to the point where it’s perfect, especially close to the end of the product development cycle. “Users are more forgiving of progress in the wrong direction than of a lack of progress. What you’ve built will never be perfect, but if it’s close enough your users will tell you how to improve it…Release early, release often.”
Marketing Blind Spot: You’re not doing any marketing. Do some marketing! “Marketing doesn’t have to cost much, but if you don’t do enough of it, you’re setting yourself up for failure.”