Posts

• Javascript Drag and Drop without jQuery UI

I’ve always used jQuery UI’s Sortable interaction for drag and drop
in Javascript, but it turns out that HTML5 makes it really easy to do without.
The best tutorial I’ve found is at HTML5 Rocks. There is also a good
reactjs-based tutorial
on Daniel Stocks’s site.

• Ruby group_by vs index_by

I’ve used Ruby’s group_by function seemingly forever: it converts
a list of objects into a hash of lists indexed by a property of your choice:

post1 = Post.new(month: "2014-01", subject: "Monkeys chasing dogs")
post2 = Post.new(month: "2014-01", subject: "Cats that look like their owners")
post3 = Post.new(month: "2014-02", subject: "Horses with a sense of humor")
[post1, post2, post3].group_by(&:month)
=> { "2014-01" => [post1, post2], "2014-02" => [post3] }

A closely related function is Active Support’s index_by. This works best if
the key is unique, and it converts a list of objects into a hash of objects
indexed by a property of your choice:

post1 = Post.new(slug: "monkeys", subject: Monkeys chasing dogs")
post2 = Post.new(slug: "cats", subject: "Cats that look like their owners")
post3 = Post.new(slug: "horses", subject: "Horses with a sense of humor")
[post1, post2, post3].index_by(&:month)
=> { "monkeys" => post1, "cats" => post2, "horses" => post3 }


This is most useful when you want a quick way to look up an object by one of
its properties. Instead of doing this, which is $O(n^2)$,

relevant_posts = slugs.map { |slug| posts.find { |post| post.slug == slug } }


you can index the posts first, which is $O(n)$:

index = posts.index_by(&:slug)
relevant_posts = slugs.map { |slug| index[slug] }

• Kent Beck Plays with Coffeescript

Kent Beck, who literally wrote the book on Extreme Programming, just made
a video where he plays with Coffeescript and shows the power of a fast feedback
loop. This shows off most of his most important programming techniques.

• Reading Code Good by Saron Yitbarek

Reading code is a great way to get better at programming, but it’s
sometimes hard to know where to start. Fortunately for you, Saron
Yitbarek
did a great talk at RailsConf 2014 called Reading
Code Good
, and she also has a great list of resources at the
accompanying web site, including some good gems to start
with if you’re a Rubyist.

One good example that isn’t listed at the site is Rake.
It’s worth reading partly because you almost certainly use it
already, and partly because it’s very well designed and written —
but mostly because you can have fun watching Jim Weirich live code
it at RubyConf Uruguay in 2013
.

• On Stable Software

Some interesting thoughts from Michel Martens on Ruby Rogues on simplicity in software:

• The reason software is often bloated is that we judge software by its adoption rate. And the easiest way to make software more popular is to make it solve a lot more people’s use cases. Thus, we drive software developers to make their products more and more complicated.
• Sites like Ruby Toolbox judge software by (among other things) how often it has been changed lately. Therefore it penalizes simple, stable packages in favour of complex, ever-changing ones.

If we really want well written, stable software, we are going about it the wrong way.

• Compiler Design in C

Many years ago, I read a wonderful book called Compiler Design in C, and the author, Allen Holub, has now made the full text available on his web site.
Even though the code is horrendously out of date and probably doesn’t even compile nowadays, it’s really easy to follow along, and it gets results quickly: by page 30, you have a working compiler for a simple language, and the rest of the book fleshes that out for increasingly realistic scenarios.

Definitely worth a (re-)read.

• Remembering Menya

Ten years ago today, on February 13, 2001, Menya died, a victim of metastatic breast cancer.

I will always remember how in 1996, after chemotherapy, surgery and radiation, her first thought was to start a support group and web site, ibcsupport.org, so people could get better information than was available in books. And how in 2000, while she was in treatment for a tumour in her brain, she started bcmets.org because there wasn’t an online group at the time that made people with metastatic breast cancer feel welcome.

I will always remember how she fought with doctors, passionately arguing her case, and winning most of the time through sheer persistence - and how she inspired other people to do likewise.

And I will always remember her last months, blind, speechless, and unable to control most of her body; reduced to a wasted heap of flesh on a bed. All she wanted was to die, but the days of defeat stretched out forever without joy.

I have come to dread each October, with its regimented optimism, its tyranny of cheerfulness, and its pink ribbons that are forgotten by half way through November. I feel for the women I know who have metastatic breast cancer, most of whom will die from it and whose researchers receive pathetically small amounts of money from the major fundraising organizations.

I’m not sure if there is a point to this, except to commemorate the tenth anniversary of the death of a tragic heroine. Menya believed that you are not properly dead as long as people remember you, so if you want to do something nice today, please read some Menya anecdotes and remember her fondly.

subscribe via RSS