My adventures rereading the Pickaxe Book have reached the chapter on Fibers. Interesting stuff. Thought I would extrapolate from their initial example. My old static pages started from a MANIFEST file that looked something like this:
index.html/babblings/index.html/babblings/2013-05-30-javascript.html/babblings/2013-04-05-perl-and-opensuse.html/babblings/2013-03-big-updates.html/babblings/seattle.html/babblings/stalkingswfans.html/babblings/bra.html/brian/index.htmlAnd so on. The path components create a topic heirarchy. There are only 89 files. This is not a lot to track, but it is enough that I can still be hazy about some high level details. For example, I have no idea how many pages are in each section.
sections = Fiber.new do File.foreach "MANIFEST" do |line| line.match %r{^/(?<path>\w+)/} do |section| Fiber.yield section[:path] end end
nilend
counts = Hash.new 0
while section = sections.resume counts[section] += 1end
counts.keys.sort.each { |section| puts "#{section}: #{counts[section]}" }Yes, this is just the example from the Pickaxe book with line.scan changed to
line.match with a slightly altered regular expression.
$ ruby nom-manifest.rbbabblings: 7brian: 2geekery: 78This isn’t that helpful though.
I already knew that the majority of my pages were in /geekery/.
Let’s adjust the regular expression so that the first two pieces of the entry count as a section.
sections = Fiber.new do File.foreach "MANIFEST" do |line| line.match %r{ ^/(?<path>\w+ # main section: /geekery (?:/\w+)?) # subsection: /ruby / # stop at path separator }x do |section| Fiber.yield section[:path] end end nilendNow I’m looking for possible subsections and lumping them with the top level section. Does this change get me more useful information (for varying definitions of useful)?
$ ruby nom-manifest.rbbabblings: 7brian: 2geekery: 2geekery/editors: 3geekery/js: 1geekery/lisp: 1geekery/osx: 1geekery/parrot: 17geekery/perl: 13geekery/php: 2geekery/python: 9geekery/rakudo: 3geekery/rebol: 10geekery/ruby: 10geekery/tools: 2geekery/unix: 2geekery/xml: 2Yeah. It does. I can now see that the most of my static pages are about Parrot or Perl.
I recognize that all I’m doing in this example is shuffling complexity around. There’s nothing in the task that screams “OMG YOU NEED FIBERS TO DO THIS!” Still - I need to figure this stuff out somehow.
Anyways, back to work.