Skip to content
Jason A. Heppler

Microblog

Microblog

Searching My Brain

I’ve long thought of my blog as a public place where I can share thoughts, tricks, and tips. Most of the things here are likely more useful for me than anyone else, but I share things because I assume the things that I find interesting are interesting to others as well. Not to mention that the places where I learn the most are free blog posts and web resources, and my blog is a way of paying it forward.

Since my blog is my public brain, I often find myself searching the site for things. I don’t use any built-in search, so I often turn to the site-specific search in DuckDuckGo. The task is simple. Adding the line:

site:jasonheppler.org

to search terms restricts the search to that site. Google and Bing work the same way. To make the process a bit faster and less prone to typos I use a TextExpander snippet.

TextExpander

Nothing clever, but useful. TextExpander can be much more powerful, but small tricks like this help remove friction in my workflow.

Tech life

Star Wars Episode VII May Have Found Its Writer

Claude Brodesser-Akner says that Star Wars Episode VII may be written by Michael Arndt:

Informed sources tell Vulture that Star Wars: Episode VII has found a leading candidate to write the film’s screenplay: Michael Arndt, the Pixar favorite who was nominated for an Oscar for Toy Story 3, won an Oscar for Little Miss Sunshine, and wrote The Hunger Games: Catching Fire, which is currently shooting. Insiders confirm that Arndt has written a 40- to 50-page treatment for the film and is likely to be at least one of the writers when the Disney/Lucasfilm project begins shooting in 2014.

A good move, and hopefully evidence of a fruitful talent share between Pixar and Star Wars.

Personal

Africa's Silicon Savannah

David Smith writes about Africa’s Silicon Savannah in Kenya, where technology companies are beginning to establish themselves:

If there is such a thing as an African version of California’s Silicon Valley, the country that is arguably leading the race to the future is Kenya.

Household tech names such as Google, Intel, Microsoft, Nokia and Vodafone all have a presence here, and IBM recently chose Nairobi for its first African research lab.

Kenyans enjoy faster broadband connections than their counterparts in Africa’s economic powerhouse, South Africa. And the government plans to build a $7bn (£4.36bn), 5,000-acre technology city that is already being branded Africa’s “Silicon Savannah”.

How did Kenya – a nation that still has its share of poverty and ethnic conflict – get here? “It started as a joke,” said Dr Bitange Ndemo permanent secretary at the information and communications ministry. “We said we wanted to beat South Africa – and we did it.”

Tech life

Opening Marked in Vim

I am a big fan of Brett Terpstra’s Marked.app for previewing Markdown documents. I wanted a way to launch Marked from within vim so I can preview what I’m writing as I am working. The task is easy. In your .vimrc file, add the line:

:nnoremap <leader>ma :silent !open -a Marked.app '%:p'<cr>

I have my leader mapped to , (comma), so if I want to launch Marked in a markdown file I’m writing, I just type ,ma and it launches the app.

UPDATE 10/16/12
Lincoln Mullen points out that console vim does not redraw after :silent and modified the command slightly:

:nnoremap <leader>ma :silent !open -a Marked.app '%:p' :redraw!<cr>

Tech life

Better Web Scraping with Nokogiri

When I wrote The Rubyist Historian a year ago, I was still getting familiar with the ins and outs of Ruby (and, truth be told, I am still doing so – it will take a long time before I, if ever, call myself a programmer). Looking back on the word count program I wrote at the end, I’ve realized a big error: I used regular expressions to parse a webpage.

There’s a much more effective way to do it: with the Ruby library Nokogiri. Nokogiri is built for HTML, XML, and SAX parsing and includes features that allows you to search for specific CSS3 or XPath selectors. Install the package through Ruby gems (sudo gem install nokogiri) and you’ll be good to go.

Let’s say I wanted to do some text analysis on the books written by William F. Cody. On the Cody Archive, we currently have three of these books digitized, edited, and ready to go. They’re encoded with TEI standards and include metadata and information you might want for more sophisticated types of analysis. But to work with them, let’s say I’d like to have three clean copies of the text on my local machine without any markup included – just plain, clean, flat text files. Using Nokogiri, the process is pretty straightforward.

Fire up your text editor of choice, and write:

#!/usr/bin/env ruby

# Name: grabtext.rb
# By: Jason Heppler
# Last Modified Fri Oct 12 14:43:58 2012
#
# This script uses Nokogiri to grab the text only between the 'text' tag
# in XML files. Modify as you need. 
# Usage: ./grabtext.rb path/to/file > output.txt

require 'rubygems'
require 'nokogiri'
require 'open-uri'

doc = Nokogiri::HTML(open(ARGV[0]))

doc.search('text').each do |link|
    puts link.content
end

Now I can run it from the command line (don’t forget to chmod the script):

$ ./grabtext.rb http://codyarchive.org/texts/wfc.bks00007.xml > autobiography.txt

For your own purposes, you may have to make some edits to the code. In my case, I’m parsing an XML file that includes the tag text and, therefore, I tell Nokogiri to look for that with doc.search(’text’). The XML file looks something like this:

<TEI xml:id="wfc.bks00007" xmlns="http://www.tei-c.org/ns/1.0">
<teiHeader>
...
</teiHeader>
<text> <!-- the script grabs the text from here... -->
<front>
<pb facs="wfc.bks00007.006"/>
<div1>
<figure n="illustration">
<p>Yours Sincerely, W. F. Cody</p>
</figure>
</div1>
<pb facs="wfc.bks00007.007"/>
<titlePage>
<docTitle>
<titlePart>THE LIFE OF
<lb/>
HON. WILLIAM F. CODY
<lb/>
KNOWN AS
<lb/>
BUFFALO BILL

...

<p>After a successful tour of six weeks on the Pacific Slope, thus ending the season of 1878-79, I am at my home at North Platte, Nebraska, for the summer; and thus ends the account of my career as far as it has gone.</p>
<ab>THE END.</ab>
</div1>
</body>
</text> <!-- ...down to here -->
</TEI>

I don’t want any of the TEI header information, so using Nokogiri I can grab everything between the text tag. This leaves me with the raw text of the XML file without any of the markup or header information.

I’m becoming more and more convinced that at least half of the work I do in digital history is cleaning up and preparing data so it can be usable. I find this little script to be handy for doing a quick grab of a site’s contents, and because Nokogiri is incredibly powerful it can chug through web pages that aren’t well-formed or valid markup. It’s faster than wget and, unlike wget, leaves me with plain text that I can start to work with right away.

UPDATE: The program can be simplified slightly by changing the loop:

#!/usr/bin/env ruby

require 'rubygems'
require 'nokogiri'
require 'open-uri'

doc = Nokogiri::HTML(open(ARGV[0])) #input
doc.search('text').each { |link| puts link.content } #plain text output

Programming

The Blossom Coffee Machine

The Verge writes about an $11,000 coffee machine constructed with exotic materials and tooled to brew the perfect cup of coffee:

Blossom isn’t looking to steal sales from the likes of Keurig, not yet at least. Instead, the company is gunning straight for the high-end, extreme coffee enthusiast market with its Blossom One Limited brewer. The $11,111 machine is hand-made with exotic materials like mahogany and teak, and Blossom is even hand-delivering it to customers that are willing to plunk down that kind of money for a coffee maker. But while the One Limited has some exotic materials, it’s the integration of new technology with the traditional methods of making coffee that has our interest piqued.

Whoh.

Coffee

Newsletter

Occasional writing on the American West, agricultural history, and political culture.