Categories
Uncategorized

“Rails to Victory”

Here’s a still from what I assume is a propaganda film from World War II titled Rails to Victory. If any of you are planning to do presentations covering the topic of Rails and are looking for some graphics for your slides, you might want to consider this one:

Opening shot from the film \"Rails to Victory\"
Click the photo to see a larger version.
Photo courtesy of Miss Fipi Lele.

Categories
Uncategorized

Take Hampton’s Ruby Survey!

\"Take Hampton\'s Ruby Survey\": Hampton Catlin pointing at his survey, projected on a screen
Photo by rcoder.
Click the photo to see the original on its Flickr page.

Hampton “HAML” Catlin of Unspace (you know, the development shop that put RubyFringe together) has created a survey that he’d like as many people who code in Ruby to take. It’s quick and painless, and he’ll share the data once he’s compiled it.

Categories
Uncategorized

They Know Their Market

Here’s a photo from a t-shirt stall at the San Diego Comic-Con, which took place this past weekend:

T-shirt sizes at San Diego ComicCon: XXL and XXXL
Photo courtesy of Miss Fipi Lele.

Categories
Uncategorized

Enumerating Enumerable: Enumerable#each_slice

Enumerating Enumerable

Ten installments already? That’s right, this is the tenth Enumerating Enumerable article. As I’m fond of repeating, this is my little contribution to the Ruby community: a series of articles where I attempt to do a better job at documenting Ruby’s Enumerable module than Ruby-Doc.org does, with pretty pictures and more in-depth examples!

In this article, I’m going to cover each_slice, which got introduced in Ruby 1.9.

If you missed any of the earlier articles, I’ve listed them all below:

  1. all?
  2. any?
  3. collect / map
  4. count
  5. cycle
  6. detect / find
  7. drop
  8. drop_while
  9. each_cons

Enumerable#each_slice Quick Summary

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

In the simplest possible terms Given a number n, split the array into n-element slices (if the number of elements in the array isn’t evenly divisible by n, just put the remaining elements in the last slice), then iterate through those slices.
Ruby version 1.9 only
Expects
  • A number n describing the size of the iteration slice.
  • An optional block to receive the values from each iteration.
Returns
  • nil, if used with a block.
  • An Enumerator object that outputs n-sized slices of the collection, if used without a block.
RubyDoc.org’s entry Enumerable#each_slice

Enumerable#each_slice and Arrays

When used on an array with a block, each_slice takes a numeric argument n and splits the array into slices of length n (if the number of elements in the array isn’t evenly divisible by n, the remaining elements are put into the last slice). each_slice then iterates through the set of slices, passing each slice to the block. After the final iteration, each_slice returns nil.

Since this is yet another case when an showing an example makes things very clear, I’ll do just that, using the same example data I used in the article on each_cons:

justice_league = ["Aquaman", "Batman", "Black Canary", 
                  "Flash", "Green Arrow", "Green Lantern", 
                  "Martian Manhunter", "Superman", 
                  "Vixen", "Wonder Woman"]
justice_league = ["Aquaman", "Batman", "Black Canary", "Flash", "Green Arrow",
"Green Lantern", "Martian Manhunter", "Superman", "Vixen", "Wonder Woman"]

justice_league.each_slice(3) {|team| p team}
=> ["Aquaman", "Batman", "Black Canary"]
["Flash", "Green Arrow", "Green Lantern"]
["Martian Manhunter", "Superman", "Vixen"]
["Wonder Woman"]
=> nil

When used on an array without a block, each_slice takes a numeric argument n and returns an Enumerator that outputs slices of the array when its next method is called. Here’s an example:

teams_of_3 = justice_league.each_slice(3)
=> #<Enumerable::Enumerator:0x007fc73baa9830>

teams_of_3.next
=> ["Aquaman", "Batman", "Black Canary"]

teams_of_3.next
=> ["Flash", "Green Arrow", "Green Lantern"]

teams_of_3.next
=> ["Martian Manhunter", "Superman", "Vixen"]

teams_of_3.next
=> ["Wonder Woman"]

teams_of_3.next
=> StopIteration: iteration reached at end...
# (I'm skipping the rest of the error message)

teams_of_3.rewind
=> #<Enumerable::Enumerator:0x007fc73baa9830>

teams_of_3.next
=> ["Aquaman", "Batman", "Black Canary"]

Enumerable#each_slice and Hashes

When used on an hash with a block, each_slice takes a numeric argument n and splits the hash into arrays of length n (if the number of elements in the array isn’t evenly divisible by n, the remaining elements are put into the last slice). Within these arrays, each hash element is represented as a two-element array, with the first element being the key and the second element being the corresponding value.

each_slice then iterates through the set of arrays, passing each array to the block. After the final iteration, each_slice returns nil.

Here’s an example, using the same example data I used in the article on each_cons:

enterprise_crew = {:captain => "Picard",
                   :first_officer => "Riker",
                   :science_officer => "Data",
                   :tactical_officer => "Worf",
                   :chief_engineer => "LaForge",
                   :chief_medical_officer => "Crusher",
                   :ships_counselor => "Troi",
                   :annoying_ensign => "Crusher",
                   :attractive_ensign => "Ro",
                   :expendable_crew_member => "Smith"}
=> {:captain=>"Picard", :first_officer=>"Riker", :science_officer=>"Data",
:tactical_officer=>"Worf", :chief_engineer=>"LaForge",
:chief_medical_officer=>"Crusher", :ships_counselor=>"Troi",
:annoying_ensign=>"Crusher", :attractive_ensign=>"Ro",
:expendable_crew_member=>"Smith"}
=> nil

enterprise_crew.each_slice(3) {|team| p team}
=> [[:captain, "Picard"], [:first_officer, "Riker"], [:science_officer, "Data"]]
[[:tactical_officer, "Worf"], [:chief_engineer, "LaForge"],[:chief_medical_officer, "Crusher"]]
[[:ships_counselor, "Troi"], [:annoying_ensign, "Crusher"], [:attractive_ensign,  "Ro"]]
[[:expendable_crew_member, "Smith"]]
=> nil

When used on a hash without a block, each_slice takes a numeric argument n and returns an Enumerator that outputs arrays when its next method is called. Here’s an example:

away_teams_of_3 = enterprise_crew.each_slice(3)
=> #<Enumerable::Enumerator:0x007fc73ba44c50>

away_teams_of_3.next
=> [[:captain, "Picard"], [:first_officer, "Riker"], [:science_officer, "Data"]]

away_teams_of_3.next
=> [[:tactical_officer, "Worf"], [:chief_engineer, "LaForge"], [:chief_medical_officer, "Crusher"]]

away_teams_of_3.next
=> [[:ships_counselor, "Troi"], [:annoying_ensign, "Crusher"], [:attractive_ensign, "Ro"]]

away_teams_of_3.next
=> [[:expendable_crew_member, "Smith"]]

away_teams_of_3.next
=> StopIteration: iteration reached at end...
# (I'm skipping the rest of the error message)

away_teams_of_3.rewind
=> #

away_teams_of_3.next
=> [[:captain, "Picard"], [:first_officer, "Riker"], [:science_officer, "Data"]]

Categories
Uncategorized

Tucows (Re)Introduces OpenSRS

I’m always happy to point out cool things that my former employer, Tucows, is up to (from 2003 to 2007, I was their Tech Evangelist). The latest one is one I’ve long supported: pulling their reseller services under a single, well-known and trusted name, OpenSRS, and a gorgeous new brand identity:

OpenSRS\' new brand identity

OpenSRS now refers to a whole slew of services: domain name registration, SSL certificates, email and “personal names” (white label access to their portfolio of common North American and European surname domains), all of which are accessible via control panel or API.

Here’s what they have to say:

Don’t mistake this for a simple re-brand. Yes, we have a new logo, and a snazzy new website, but there’s a lot more to what we’re doing here than a fresh coat of paint and some new pictures on the wall.

Back in 1999 when Tucows first started selling domain names as one of the original ICANN accredited registrars, we wanted to bring Internet service providers something they hadn’t been accustomed to getting when it came to domain names: customer service. We launched back then with a real customer focus that extended throughout everything we did.

The logo also proudly proclaims that OpenSRS is “Reseller Friendly.” That is more than just a slogan, or a tag line – it’s a promise. Like the customer focused wholesale domain name business that launched in 1999 as OpenSRS, today we remain dedicated to providing the best possible experience for our resellers.

That means resellers can expect easily accessible customer support with knowledgeable people on the other end of the phone line. And it means products and services that are created and implemented with the specific needs of the reseller in mind. That Reseller Friendly attitude and approach extends throughout every aspect of our business.

We’re putting that Reseller Friendly promise prominently on display, right in our logo. We’re not only rebranding our wholesale Internet Services business as OpenSRS, but we’re re-dedicating ourselves to the approach that, with your help, made us so successful over the past nine years and will continue it into the future.

For more, including a video interview featuring my old boss Ken Schafer (VP Marketing and Product Management), check out this entry in the Tucows Reseller Blog.

Categories
Uncategorized

Enumerating Enumerable: Enumerable#each_cons

Enumerating Enumerable

Welcome to the ninth installment of Enumerating Enumerable, the series of articles where I attempt to do a better job at documenting Ruby’s Enumerable module than Ruby-Doc.org does.

I’m going through the Enumerable‘s methods in alphabetical order, and we’ve reached the methods that are variations on each In this article, I’m going to cover each_cons, which got introduced in Ruby 1.9.

If you missed any of the earlier articles, I’ve listed them all below:

  1. all?
  2. any?
  3. collect / map
  4. count
  5. cycle
  6. detect / find
  7. drop
  8. drop_while

Enumerable#each_cons Quick Summary

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

In the simplest possible terms Think of each_cons as an each that takes a number n and spits out n elements at a time.
Ruby version 1.9 only
Expects A number n describing the number of elements to be fed to the block.
Returns
  • nil if used with a block
  • An Enumerator object that outputs n-sized consecutive array slices of the collection if used without a block.
RubyDoc.org’s entry Enumerable#each+cons

Enumerable#each_cons and Arrays

When used on an array and given a block and a number n as an argument, each_cons is like an each that goes through each element in the array and outputs an n-sized array slice of the original array starting at the current element.

each_cons is one of those methods that’s really tough to describe. This is one of those cases where a demonstrating trumps describing…

justice_league = ["Aquaman", "Batman", "Black Canary", \
                  "Flash", "Green Arrow", "Green Lantern", \
                  "Martian Manhunter", "Superman", \
                  "Vixen", "Wonder Woman"]
=> justice_league = ["Aquaman", "Batman", "Black Canary", "Flash", "Green Arrow",
"Green Lantern", "Martian Manhunter", "Superman", "Vixen", "Wonder Woman"]

justice_league.each_cons(3) {|team| p team}
=> ["Aquaman", "Batman", "Black Canary"]
["Batman", "Black Canary", "Flash"]
["Black Canary", "Flash", "Green Arrow"]
["Flash", "Green Arrow", "Green Lantern"]
["Green Arrow", "Green Lantern", "Martian Manhunter"]
["Green Lantern", "Martian Manhunter", "Superman"]
["Martian Manhunter", "Superman", "Vixen"]
["Superman", "Vixen", "Wonder Woman"]
=> nil

Note that in this case, each_cons returns nil.

each_cons can also be used without providing a block. In this case, you’re using it to create an Enumerator object that you can then use to spit out array slices when you call its next method:

# Let's create an enumerator that we can use to give us three-person
# superhero teams
teams_of_3 = justice_league.each_cons(3)
=> #

# Let's get the first team of 3
teams_of_3.next
=> ["Aquaman", "Batman", "Black Canary"]

# Now the next one...
teams_of_3.next
=> ["Batman", "Black Canary", "Flash"]

teams_of_3.next
=> ["Black Canary", "Flash", "Green Arrow"]

teams_of_3.next
=> ["Flash", "Green Arrow", "Green Lantern"]

# Let's go back to the first team of 3
teams_of_3.rewind
=> #

teams_of_3.next
=> ["Aquaman", "Batman", "Black Canary"]

Enumerable#each_cons and Hashes

When used on a hash and given a block and a number n as an argument, each_cons is like an each that goes through each element in the array and outputs an n-sized array slice of the hash starting at the current element. Note that in the process, hash elements are converted into two-element arrays where the first element contains the key and the second element contains the corresponding value.

Again, examples speak louder than descriptions:

enterprise_crew = {:captain => "Picard",
                   :first_officer => "Riker",
                   :science_officer => "Data",
                   :tactical_officer => "Worf",
                   :chief_engineer => "LaForge",
                   :chief_medical_officer => "Crusher",
                   :ships_counselor => "Troi",
                   :annoying_ensign => "Crusher",
                   :attractive_ensign => "Ro",
                   :expendable_crew_member => "Smith"}
=> {:captain=>"Picard", :first_officer=>"Riker", :science_officer=>"Data", :tact
ical_officer=>"Worf", :chief_engineer=>"LaForge", :chief_medical_officer=>"Crush
er", :ships_counselor=>"Troi", :annoying_ensign=>"Crusher", :attractive_ensign=>
"Ro", :expendable_crew_member=>"Smith"}

enterprise_crew.each_cons(3) {|team| p team}
=> [[:captain, "Picard"], [:first_officer, "Riker"], [:science_officer, "Data"]]
[[:first_officer, "Riker"], [:science_officer, "Data"], [:tactical_officer, "Worf"]]
[[:science_officer, "Data"], [:tactical_officer, "Worf"], [:chief_engineer, "LaForge"]]
[[:tactical_officer, "Worf"], [:chief_engineer, "LaForge"], [:chief_medical_officer, "Crusher"]]
[[:chief_engineer, "LaForge"], [:chief_medical_officer, "Crusher"], [:ships_counselor, "Troi"]]
[[:chief_medical_officer, "Crusher"], [:ships_counselor, "Troi"], [:annoying_ensign, "Crusher"]]
[[:ships_counselor, "Troi"], [:annoying_ensign, "Crusher"], [:attractive_ensign, "Ro"]]
[[:annoying_ensign, "Crusher"], [:attractive_ensign, "Ro"], [:expendable_crew_member, "Smith"]]
=> nil

As with arrays, each_cons, when used on a hash, returns nil.

Again, as with arrays, each_cons can also be used without providing a block to create an Enumerator:

# Starfleet has decided to let the ship's computer determine
# the away teams, which are groups of 3
away_teams_of_3 = enterprise_crew.each_cons(3)
=> #

# Okay, who's the first away team?
away_teams_of_3.next
=> [[:captain, "Picard"], [:first_officer, "Riker"], [:science_officer, "Data"]]

# Let's get the next one
away_teams_of_3.next
=> [[:first_officer, "Riker"], [:science_officer, "Data"],
[:tactical_officer, "Worf"]]

away_teams_of_3.next
=> [[:science_officer, "Data"], [:tactical_officer, "Worf"],
[:chief_engineer, "LaForge"]]

# Let's go back to the first away team
away_teams_of_3.rewind
=> #

away_teams_of_3.next
=> [[:captain, "Picard"], [:first_officer, "Riker"], [:science_officer, "Data"]]

Categories
Uncategorized

Notes from Damian Conway’s Presentation

Damian Conway - July 16, 2008

Here are my notes on Damian Conway’s presentation, Temporally Quaquaversal Virtual Nanomachine Programming in Multiple Topologically Connected Quantum-Relativistic Parallel Timespaces…Made Easy, which he gave on Wednesday, July 16th at the University of Toronto’s Bahen Centre. This presentation was a dry run for the presentation he made on Tuesday at the O’Reilly Open Source Conference (OSCON) 2008. The talk ran for about two hours, and the time allotted for it at OSCON 2008 was one hour. He incorporated parts of earlier talks into this one, so I suspect that he condensed those parts.

Damian was in fine form and it was good to catch another one of his funny, off-the-wall presentations; it was a good warm-up for RubyFringe.

- I'd just celebrated my 42nd birthday was doing some reflection
- I thought maybe now it was time to get serious [yeah, right]

- The original title for this presentation was going to be something
  like "The lies we tell ourselves"
- Consider the myths that we in the F/OSS world tell ourselves:
    - Consider ESR's line, "Given enought eyeballs, all bugs are shallow"
    - Speaking from experience, that's not true.
      What *is* true is: "Given eniugh eyeballs, all *bug reports*
      are shallow"
    - Then there's the line "Fast, cheap, good: pick any two."
    - What closer to reality? "Fast, cheap, good: pick at most one."
    - The biggest lie is probably "Information wants to be free"
    - You might as well be saying
        - "Beer wants to be drunk"
        - "Virginity wants to be lost"
        - or...

Slide from Damian Conway\'s presentation: \"An iPhone data plan wants to be vastly more expensive in Canada\"

        - An iPhone data plan wants to be vastly more expensive
          in Canada

- The bad angel on my shoulder has been telling me lies: "Damian, you're not
  just an amazing hacker, you're a deep thinker as well!"
- The truth is that I'm not good at analyzing reality -- I'm good at
  *manipulating reality via language*

- That's a popular lie we tell ourselves: that "Smart is distributive"
- In other words, we think that if we do well in one area, perhaps we
  can do well in others
- Genius is a *vector*, not a *field*
- Convincing ourselves that genius is distributive is a sign of aging

[ Damian launches into funny photo essay showing his hair greying
  after joining the world of Perl programming. He then shows Larry
  Wall over the same time period, noting that he looks pretty much
  the same. He hypothesizes that Larry doesn't age, and as proof,
  shows an amusing series of Photoshopped photos of Larry through
  the ages, ending with ancient Egypt. ]
- You can derive two bits of knowledge from all this:
    - Perl 5 isn't line noise, it's *hieroglyphics*!
    - As for when Perl 6 is coming out, keep in mind that
      Larry has all the time in  the world

\"Larry Wall does not age\" slide from Damian Conway\'s presentation

- Back in 2000, I decided to introduce superpositions (the ones from
  quantum physics) into Perl.
- There's the "any" function, which is not so rigid, which is why
  I call it the "Canadian superposition"
- There's the "all" function, which is quite rigid, which is why
  I call it the "American superposition" (which will come to liberate
  you with its troops!)
- Superposition functions are constant-time operations
- You can ue them now with "use Quantum::Superpositions"
- They're part of Perl 6
- Other junction functions:
    - none
    - one

[ He goes into a discussion about relativity, light cones, quantum
  physics and the whole "Brief History of Time" ball of wax,
  a condensed version of his "Time::Space::Continuum talk.
  I now look at gravitational lensing in a different way! ]

- I'm always chasing after new mental models of programming
- While doing that, I keep this motto in mind: Progressio defectum postulat
  ("Progress requires failure")

- There's something I call Rod Logic: that's computation via levers,
  gears and cams
- Doesn't "Rod Logic" sound like a 1950's science fiction hero
  written for boys?

\"Rod Logic book covers\" slide from Damian Conway\'s presentation

- Think of Babbage's engines
- Eric Drexler has shrunk rod logic: using carbon nanotubes as
  nano-sized levers, he's made mechanical logic gates
- Can't I use rod logic for Perl?
- I created a straight line language that could charitably be described
  as "Readability suboptimal"

[ He demonstrates a language that's made of nothing but straight-line
  characters -- _, -, [, ], <, >, \, |, /. It makes Perl look like
  a storybook for first grade readers in comparison. ]

[ Discussion of positrons -- electrons with positive charge -- and
  Feynman diagrams. One of the consequences of drawing the release
  of a positron on a Feynman diagram is that they are travelling
  leftwards on the "time" axis. They are going backwards in time!

  He then showed an application that takes the idea of particles
  travelling backwards in time and applied them to variables.
  The end result? Positronic variables! ]

- use Positronic::Variables
- They come into existence at end of block, and travel backwards
  in runtime
- With a positronic variable, you can declare a variable that
  holds values you'll need later, and they'll travel back in time
  where your program "catches up" with them later
- Makes the square root finding algorithm so much easier!
- The trick is that positronic variable programs get run through
  a preprocessor that repeatedly runs through the app
- This will works only on programs with convergent algorithms
- "I will eventually develop a positronic debugger,
  and I have been using it."

- And finally, if you look at everything I talked about this evening,
  you have the title of this talk explained: "Temporally Quaquaversal
  Virtual Nanomachine Programming in Multiple Topologically Connected
  Quantum-Relativistic Parallel Timespaces…Made Easy.

===

Q & A

- Earlier at lunch with Richard Dice, I told him: "There's no crowd like
  a Toronto crowd." You're wonderful, thank you!

- What's up with Perl 6?
    - For the past few years, there have been on average hundreds
      of doc changes committed
    - This year, there are fewer than 100
    - What does it mean? That we got it right
    - And yes, Larry's implementing
    - Which means that we are in a new phase in the development
      of Perl 6: the end phase"
    - This is going to be an awesome language
    - I've been working with early releases of Perl 6, and I've noticed
      how irritating it is to go back to Perl 5

- Now let me talk about Perl 5.10
    - There are many improvements that are largely about making life easier
      and programming less annoying.
    - Consider the say function -- simple, but not having to add a newline
        and the end of print strings makes a lot of difference
    - That's the whole point -- they looked at the really basic stuff
      that we do all the time and made it simpler
    - Another example, the "//" operator, called "defined or". It
      returns the left argument if it's defined, otherwise
      it returns the returns the right argument
    - At long last, Perl has a switch statement!

- Does any of this stuff lend itself to multicore?
    - Junctions and superpositions are a natural fit for multiprocessors
    - With languages that have junctions, it should at least be possible
      to automatically farm junction operations to parallel processors

- How hard was it to write your modules based on quantum physics?
    - Easier than you think
    - What helped what that I had the quantum physics metaphor to guide me
    - The trick is to understand the metaphor,
      and implement it consistently
    - Remember: quantum mechanics is one of the most rigorously
      tested systems we've ever conceived

- Are positronic variables another way of implementing
  constraint-based programming?
    - YES!
    - In fact, this is a good time to explain why I do all this
      odd stuff, taking concepts from quantum physics and then applying
      them to Perl
    - I use odd metaphors to think up new programming paradigms