mahiwaga

I'm not really all that mysterious

The Protracted Death Throes of Flash

Flash is dead. It just hasn’t stopped moving yet.

Adobe confirms major Flash vulnerability, and the only way to protect yourself is to uninstall Flash • 2015 Oct 15 • Zach Epstein • BGR

A critical vulnerability (CVE-2015-7645) has been identified in Adobe Flash Player 19.0.0.207 and earlier versions for Windows, Macintosh and Linux. Successful exploitation could cause a crash and potentially allow an attacker to take control of the affected system.

Security Advisory for Adobe Flash Player • APSA15-05 • CVE-2015-7645 • 2015 Oct 14 • Adobe Security Bulletin

Adobe did release a patch immediately after this advisory came out, but I think I will be following this advice instead:

How to uninstall Flash Player from your Mac • 2015 Oct 15 • Susie Ochs • Macworld

posted by Author's profile picture mahiwaga

Fake Grammar Rules

I don’t know/remember who to blame for teaching me the bogus rule that you can’t use “whose” to refer to nouns that are not people, but I find myself constantly second-guessing myself when I do use it.

Whose for Inanimate Objects • Can you use “whose” to refer to inanimate objects? • 2008 May 23 • Bonnie Mills • QuickAndDirtyTips.com

In some cases, you might be able to use of which, but most of the time your sentence will sound stilted and your sentence flow will be ruined. The three major sources I referred to all agree that of which is not an ideal solution to the whose conundrum.1,2,3 The American Heritage Guide to Contemporary Usage and Style states, “This is one case in which the cure could be worse than the disease.”

  1. American Heritage Guide to Contemporary Usage and Style. Boston: Houghton Mifflin Company, 2005, pp. 505-6.

  2. American Heritage Dictionary of the English Language. Fourth edition. Boston: Houghton Mifflin Company, 2006, p. 1965.

  3. Burchfield, R. W, ed. The New Fowler’s Modern English Usage. Third edition. New York: Oxford, 1996, p. 563.

posted by Author's profile picture mahiwaga

and in Firefox

I guess I haven’t written HTML in a long time. I only just learned about the <details> and <summary> tags.

I then quickly learned that Firefox doesn’t yet implement it and the bug report has been outstanding since 2010.

posted by Author's profile picture mahiwaga

List Manipulation

I am amused (because I am a weirdo) by how common the paradigm of manipulating lists is in computer programming, specifically, the need to separate the first element in a list from the rest of the list.

My very first exposure to dealing with lists was Logo, specifically, the first and butfirst primitives.

Of course, since Logo is technically a dialect of Lisp, these primitives are really just synonyms for car and cdr, which I remember from my college freshman roommate’s attempt to teach me Scheme. (I don’t know why, but I honestly could never get a hang of all those parentheses.)

My second exposure to lists (specifically, linked lists) was when I was studying for the A.P. Computer Science exam senior year in high school, even though I didn’t take the A.P. Computer Science class. Pascal was the language of choice at the time, and while I learned how to use pointers and how to insert and delete elements, I remember it requiring a lot of low-level programming and longed for the easy elegance of interpreted Logo.

So I feel like I’ve come circle dealing with lists in Ruby. Ruby doesn’t really have a list type, but since Arrays can be dynamically resized (unlike in Pascal or even many interpreted BASIC dialects), they can easily be used as such. Arrays have a #first method but they don’t have a corresponding #butfirst (Apparently that’s what Matz would call it if it existed. Yay Logo!)

But I guess it’s easy enough to use Array.drop(1) (or even extend the Array class with a #butfirst method that serves as an alias for Array.drop(1))

Oh, and there’s also the splat operator in Ruby:

The Strange Ruby Splat • 2011 Jan 21 • Adam Sanderson • End of Line

posted by Author's profile picture mahiwaga

Unwrapping Nodes with Nokogiri

I learned a lot about the Nokogiri gem (used to parse and manipulate XML and HTML) when I wrote a script to download all my FriendFeed posts.

One thing I couldn’t figure out how to do was how to unwrap a node:

quick-brown-fox.html before transformation

<html>
<head>
<title>example</title>
</head>
<body>
<p>The <font face="Verdana" size="16">quick brown <a href="https://en.wikipedia.org/wiki/Fox" title="Fox • Wikipedia">fox</a></font> jumped over the <font face="Verdana" size="16">lazy <a href="https://en.wikipedia.org/wiki/Dog" title="Dog • Wikipedia">dog</a></font>.
</p>
</body>
</html>

quick-brown-fox.html after transformation

<html>
<head>
<title>example</title>
</head>
<body>
<p>The quick brown <a href="https://en.wikipedia.org/wiki/Fox" title="Fox • Wikipedia">fox</a> jumped over the lazy <a href="https://en.wikipedia.org/wiki/Dog" title="Dog • Wikipedia">dog</a>.
</p>
</body>
</html>

Now, one could simply use XSLT:

unwrap-font.xsl • XSL stylesheet to unwrap <font> tag

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:template match="font">
    <xsl:apply-templates />
  </xsl:template>
  
  <xsl:template match="/ | @* | node()">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()" />
    </xsl:copy>
  </xsl:template>
  
</xsl:stylesheet>

Ruby code to perform XSL transform

require 'nokogiri'

input = Nokogiri::HTML(open('quick-brown-fox.html'))
template = Nokogiri::XSLT(open('unwrap-font.xsl'))

output = template.transform(input)

…but this seems like overkill.

Instead, you could do this:

Ruby code to remove <font> tags

document = Nokogiri::HTML(open('quick-brown-fox.html'))
nodeset = document.xpath('//font')
nodeset.each { |node|
  node.replace(node.children)
}

(I originally found the following code for unwrapping nodes, but it doesn’t really do what I want it to since it appends the contents of the <font> tags to the end of the <p> instead of right after the <font> tag.)

posted by Author's profile picture mahiwaga

The Human Brain and Cooking

This is an old TED talk but I heard it for the first time this past Saturday. The theory is that the reason why human intellectual capacity disproportionately surpasses the intellectual capacity of other species is because we learned how to cook.

(crossposted on Facebook)

What is so special about the human brain? • 2013 Jun • Suzana Herculano-Houzel • TED

The line of reasoning is that what gives us our intellectual capacity is the massive number of neurons in our cerebral cortex—it gives us the capacity to plan and order tasks and make decisions and to model reality, among other things.

The massive number of neurons in the cerebral cortex require a lot of energy to maintain proper function. Without cooking, we would need to devote more than 9 hours a day to obtain and consume the necessary number of calories.

Cooking predigests food, making it easier for your small intestine to absorb and process nutrients. And your intestinal mucosa doesn’t need to spend as much energy synthesizing the necessary enzymes to break down raw food like other animals do.

This is yet another reason why I am so skeptical of the idea that “unaltered” food is better for us. Cooking is obviously a major modification of food.

posted by Author's profile picture mahiwaga

Markdown Implementation Lock-In

For a while, I was thinking about fleeing Jekyll for some other static-site generator.

The main reason was that it was taking a million years1,2 for Jekyll to build my blog.

But I’ve since gotten used to the kramdown flavor of Markdown and kramdown doesn’t exist in other languages other than Ruby. In fact, most languages only support a version of CommonMark at best and having to edit out all the extensions I use (specifically footnotes, inline attribute lists, and Markdown embedded in HTML blocks) would be very daunting at this point.

The State of Markdown • 2014 Nov 30 • Phil Sturgeon

  1. Excessive Build Times • 2015 Sep 21 • mahiwaga.net

  2. A Little Better • 2015 Sep 23 • mahiwga.pw

posted by Author's profile picture mahiwaga