Categories
Uncategorized

How to Read C Declarations

Here’s a handy guide to reading C declarations, where things can get very confusing very quickly. Quick — what’s being declared in the line “int (*(*vtable)[])();” ?

Categories
Uncategorized

Your First Warning: DemoCamp 17 Takes Place on Monday, February 25th

DemoCamp logo

That’s right — DemoCamp, the gathering of the bright lights of Toronto’s tech community takes place in a couple of weeks! Here are the details:

  • When: Monday, February 25th, from 6:00 p.m. to 9:00 p.m. (Doors typically open around 5 – 5:30)
  • Where: Toronto Board of Trade, 1 First Canadian Place (King and Bay), Toronto, Ontario, Canada
  • Niceties include: Free food and a cash bar
  • Cost: Free, but you have to sign up, and there’s also the option of making a donation (see below)
  • After-party: After the presentations, we’ll adjourn to the nearby Duke of Westminster (77 Adelaide Street West)

I’ll go into more detail about DemoCamp in a later posting, but in the meantime, here are some handy links to get you started:

  • We use this Eventbrite page for sign-ups. You need to sign up to attend, and there are three sign-up options:
    • You can “purchase” a free ticket, which as the name implies, means that it costs nothing
    • You can purchase a Community Supporter ticket for $5
    • You can purchase a Community All-Star ticket for $10 (I bought one just now)
  • You’ll find more details about the event at the DemoCamp 17 page on the BarCamp wiki.
  • If you want to do a demo or Ignite presentation at DemoCamp 17, sign up here.
  • DemoCamp sells sponsorships! Sponsorship means prominent placement of your logo during the opening comments, and a representative from your company or organization gets 2 minutes at the podium. Sponsorships go for a mere $200 — contact Jay Goldman for details.

As I wrote earlier, I’ll post more details later.

Categories
Uncategorized

A New ActiveMerchant Ebook

ActiveMerchant payment authorization diagram

[Via Ruby Inside] ActiveMerchant is a new PDF-format ebook covering the ActiveMerchant Ruby library for handling payments. It supports a number of payment gateways, including PayPal, Authorize.Net, and TrustCommerce. It’s a brief 74 pages long and sells for a dirt-cheap $9. I’m going to order myself a copy later today.

Categories
Uncategorized

Enumerating Ruby’s “Enumerable” Module, Part 2: “collect”, a.k.a. “map”

In the last article in this series covering the methods in Ruby’s Enumerable module, I covered all? and any?. In this installment, I’ll look at the collect method, a.k.a. the map method.

collect, a.k.a. map

  • In plain language: Create an array by performing some operation on every item in the given collection.
  • Ruby.Doc.org’s entry: Enumerable#collect / Enumerable#map
  • Expects: A block containing the operation (it’s optional, but you’re likely to use one most of the time).
  • Returns: An array made up of items created by performing some operation on the given collection.

collect and map are synonyms — you can use either. I personally prefer map as it’s shorter and makes more sense: I view the operation as using a function to map a collection to an array.

Using collect/map with Arrays

When used on an array and a block is provided, collect/map passes each item to the block, where the operation in the block is performed on the item and the result is then added to the result array. Note the the result array has the same number of elements as the given array.

[1, 2, 3, 4].map {|number| number ** 2}
=> [1, 4, 9, 16]

["Aqua", "Bat", "Super", "Wonder Wo"].map {|adjective| adjective + "man"}
=> ["Aquaman", "Batman", "Superman", "Wonder Woman"]

When the block is omitted, collect/map uses this implied block: {|item| item}, which means when applied on an array without a block, collect/map is the identity function — the resulting array is the same as the given array.

[1, 2, 3, 4].map
=> [1, 2, 3, 4]

["Aqua", "Bat", "Super", "Wonder Wo"].map
=> ["Aqua", "Bat", "Super", "Wonder Wo"]

Using collect/map with Hashes

When used on a hash and a block is provided, collect/map 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.

Each key/value pair is passed to the block, where the operation in the block is performed on the item and the result is then added to the result array. Note the the result array has the same number of elements as the given array.

burgers = {"Big Mac" => 300, "Whopper with cheese" => 450, "Wendy's Double with cheese" => 320}

# What if I had just half a burger?
burgers.map {|burger| burger[1] / 2}
=> [160, 150, 225]

burgers.map {|sandwich, calories| calories / 2}
=> [160, 150, 225]

burgers.map {|burger| "Have a tasty #{burger[0]}!"}
=> ["Have a tasty Wendy's Double with cheese!", "Have a tasty Big Mac!", "Have a tasty Whopper with cheese!"]

burgers.map {|sandwich, calories| "Have a tasty #{sandwich}!"}
=> ["Have a tasty Wendy's Double with cheese!", "Have a tasty Big Mac!", "Have a tasty Whopper with cheese!"]

burgers.map {|sandwich, calories| ["Half a #{sandwich}", calories / 2]}
=> [["Half a Wendy's Double with cheese", 160], ["Half a Big Mac", 150], ["Half a Whopper with cheese", 225]]

When the block is omitted, collect/map uses this implied block: {|item| item}, which means when applied on an hash without a block, collect/map returns an array containing a set of two-item arrays, one for each key/value pair in the hash. For each two-item array, item 0 is the key and item 1 is the corresponding value.

burgers = {"Big Mac" => 300, "Whopper with cheese" => 450, "Wendy's Double with cheese" => 320}

burgers.map
=> [["Wendy's Double with cheese", 320], ["Big Mac", 300], ["Whopper with cheese", 450]]

Special Case: Using collect/map on Empty Arrays and Hashes

When applied to an empty array or hash, with or without a block, all? always returns true.

[].map
=> []

[].map {|item| item * 2}
=> []

{}.map
=> []

{}.map {|sandwich, calories| "Have a tasty #{sandwich}!"}
=> []

In the Next Installment…

…the detect (a.k.a. find) method.

Categories
Uncategorized

Mockup vs. Reality

Pictured below are two photos:

  1. The mockup of an International Space Station module at Leicester’s National Space Centre, and
  2. The reality — a photo taken a week ago aboard the actual International Space Station.

ISS: The mockup (clean, ordered) vs. the reality (a mess of cables and gear)
Click the photo to see it at full size.
Photo courtesy of Miss Fipi Lele.

I think it’s a pretty apt visual metaphor for the difference between your application’s design and the actual implementation.

Categories
Uncategorized

Really, It IS the Only Valid Measurement of Code Quality

Comic: The only valid measurement of code quality: WTFs per minute
Click the comic to see it on its original page.

Categories
Uncategorized

Animator vs. Animation

It’ll be really amusing to Flash developers, but I think that nerds of all stripes who like action movies will love Animator vs. Animation.