Steve Friedl has a number of excellent technical explanations on his site, and his latest one, An Illustrated Guide to the Kaminsky DNS Vulnerability, is a masterpiece that does a fine job of explaining the DNS vulnerability that Dan Kaminsky found.
Copy and Paste
In the very unlikely event that you forgot what the keyboard shortcuts were…
Linux Bloat
It could be that programmers are getting larger, but it also could be that Linux Symposium is using American Apparel shirts. They’re supposedly not made in sweatshops and are made from really soft cotton, but they’re about a size smaller than the corresponding Hanes Beefy-T’s.
Attention Toronto-area developers! If you’ve got good PHP/MySQL chops (having a little experience building WordPress templates and plugins would be a bonus, but not absolutely necessary), perhaps you’d like to do a little contract work for my company, b5media. Our regular programming staff has its hands full with our core projects, so I’m using my authority as the company’s Nerd Wrangler (a.k.a. Technical Project Manager) to cast a net for local developers who’d like to work on a project or two.
I can’t go into details here on the blog — here’s what I can tell you:
- We’re a network of about 300 or so blogs and our revenue is based on advertising, which in turn is based on our readership.
- Our blogs are based on WordPress. Mark Jaquith, one of our programmers, is a WordPress core developer. As you may have already reasoned out, our stuff is based on MySQL and PHP.
- I have a couple of projects:
- A WordPress-based promo site using a customized template and featuring some custom widgets and plugins, and
- An ecommerce site that makes it easy for people to purchase ads on our blogs
If you’re picked to do the job, you’ll be working from a pretty complete spec written by someone who understands both the business and technical sides of the job: me! You’ll also be reporting to me, and I’m told that I’m a pretty good guy to work with.
There’s something to be said for face-to-face meetings and being able to walk up to the project lead and ask questions, so we’d rather hire a developer in town.
Interested? Drop me a line at my work email address — joey@b5media.com — and I’ll be happy to tell you more.
Internet Memes Timeline
Feeling nostalgic for “Ate My Balls”, “I Kiss You” or “All Your Base are Belong to Us”? The Internet Memes Timeline’s got the cure for that.
The Code_Swarm video is an interesting visualization of the evolution of the work done on the Python programming language and the people involved, tracing its evolution from late 1990 to mid-2005.
code_swarm – Python from Michael Ogawa on Vimeo.
The intro for the video says:
In 1991, Guido van Rossum released his Python scripting language to the public.
This video will take you through the history of the project, compressed into a fraction of the time.
You will see the names of developers fade in and out of prominence, while the files they work on swirl around them.
Red files are core code. Blue files are documents. Yellow files are modules. The histogram on the bottom tracks the size and time of commits. When a person makes a commit, their name stands out. The files they commit also stand out. Files grow in size every time they are committed. Files and people gradually fade when there is no activity.
We’re at lucky number 13 — the thirteenth article in the Enumerating Enumerable series, which covers the methods of Ruby’s Enumerable
module. I started this series after being disappointed with the documentation at Ruby-Doc.org.
In this article, I’m covering the find_all
— a.k.a. select
— method.
In case you missed any of the previous articles, they’re listed and linked below:
- all?
- any?
- collect / map
- count
- cycle
- detect / find
- drop
- drop_while
- each_cons
- each_slice
- each_with_index
- entries / to_a
Enumerable#find_all / Enumerable#select Quick Summary
In the simplest possible terms | Which items in the collection meet the given criteria? |
---|---|
Ruby version | 1.8 and 1.9 |
Expects | A block containing the criteria. |
Returns | An array containing the items in the collection that meet the given criteria. If no items in the collection meet the given criteria, this is an empty array. |
RubyDoc.org’s entry | Enumerable#find_all / Enumerable#select |
Enumerable#find_all / Enumerable#select and Arrays
When used on an array, find_all
and its synonym select
passes each item from the array to the block, returning an array containing only those elements in the original array for which the block returns a value that doesn’t evaluate to false
.
If no item in the array causes the block to return a value that doesn’t evaluate to false, find_all
/select
returns an empty array.
In the examples that follow (which are based on my examples for the detect
/find
method), I’ll be using the find_all
method. select
does exactly the same thing; it’s just that I prefer find_all
.
# Once again, I shall establish my "old fart" credentials classic_rock_bands = ["AC/DC", "Black Sabbath", "Queen", \ "Ted Nugent and the Amboy Dukes", "Scorpions", "Van Halen"] => ["AC/DC", "Black Sabbath", "Queen", "Ted Nugent and the Amboy Dukes", "Scorpions", "Van Halen"] # Of the bands in the array, which ones have # a name longer than 8 characters? classic_rock_bands.find_all {|band| band.length > 8} => ["Black Sabbath", "Ted Nugent and the Amboy Dukes", "Scorpions", "Van Halen"] # Which ones have a name exactly 5 characters long? classic_rock_bands.find_all {|band| band.length == 5} => ["AC/DC", "Queen"] # If no band in the array meets the criteria, # find_all returns an empty array. # Which ones have names shorter than 5 characters? classic_rock_bands.find_all {|band| band.length < 5} => []
Enumerable#find_all / Enumerable#select and Hashes
When used on a hash, find_all
/select
passes each key/value pair in the hash to the block, which you can “catch” as either:
- A two-element array, with the key as element 0 and its corresponding value as element 1, or
- Two separate items, with the key as the first item and its corresponding value as the second item.
As with arrays, find_all
/select
passes each item from the hash to the block, returning an array containing only those items in the original array for which the block returns a value that doesn’t evaluate to false
.
Note that each item in the result array is a two-element array corresponding to an item from the original hash. In this array, element 0 contains the key and element 1 contains the corresponding value.
If no item in the hash causes the block to return a value that doesn’t evaluate to false, find_all/select returns an empty array.
years_founded = {"AC/DC" => 1973, \ "Black Sabbath" => 1968, \ "Queen" => 1970, \ "Ted Nugent and the Amboy Dukes" => 1967, \ "Scorpions" => 1965, \ "Van Halen" => 1972} => {"AC/DC"=>1973, "Black Sabbath"=>1968, "Queen"=>1970, "Ted Nugent and the Amboy Dukes"=>1967, "Scorpions"=>1965, "Van Halen"=>1972} # Ruby 1.9 preserves hash order so that hashes keep the order in which # you defined them, while Ruby 1.8 puts them in some mysterious order. # All these examples are in Ruby 1.9 # Which bands were founded in 1970 or later? years_founded.find_all {|band| band[1] >= 1970} => [["AC/DC", 1973], ["Queen", 1970], ["Van Halen", 1972]] # Here's another way of phrasing it: years_founded.find_all {|band, year_founded| year_founded >= 1970} => [["AC/DC", 1973], ["Queen", 1970], ["Van Halen", 1972]] # Which bands were founded after 1980? years_founded.find_all {|band, year_founded| year_founded > 1980} => []