Programming

Writing Hexo filters

Hexo, the static blogging system that I use is very extensible and provides numerous hooks into generation pipeline.

While working on a Russian language blog that’s coming online soon, I had the opportunity to write a filter to render Cyrillic text in a different font than the rest of the body text.

Markup filter use case

I wanted to set the Cyrillic text apart both in color, typeface, and font weight. Although I could have extended Hexo using a new tag, I decided to use a filter so that after rendering HTML anywhere on the blog, items demarcated by double pipes || would be replaced by a new <span>.

Fine-tuning caching for S3-hosted static blogs using AWS CLI

Because the blogging system that I use doesn’t apply finely grained object-level caching rules, I end up with objects such as images that cache appropriately but an index.html page that does not. I don’t want client browsers to hang on to the main index.html page for more than an hour or so because it should update much more frequently than that as its content changes.

It’s possible that I could dig around under the hood of hexo and create a version that applies customized caching rules. Instead, I make a second pass over the content, adjusting the Cache-Control and other metadata according to my needs. For this task I use the Amazon Web Services command line interface AWS-CLI.

anki_tool: low level manipulation of Anki databases

Speaking of Anki, here’s a Swiss Army knife of database utilities that provides searching, moving and renaming functions from the command line.

On GitHub.

You can do things like this to rename and collect tags:

$ anki_tool mv_tags '(dinosaur|mammal)' animal

Looks cool.

JavaScript in Anki cards

[N.B. 2016-03-26 Nathan Ifill pointed out that it is possible to use Anki’s built-in conditional replacement feature to do what I’m illustrating. I’ll have to work on another example!]

Anki is a widely-used flashcard application. If you’re learning a foreign language and you’re not using Anki, you should be.

If you are using Anki and are picky about the appearance of the cards, you should know that JavaScript can be used in the card template. This opens up a number of possibilities for dynamic cards. I’m just touching on the technique here.

Trump meets computational linguistics

Trump orating

“I actually called her, and she never mentioned my name. You know, I - when I sold - oh, did I get a call from one of the Environmental Protection Agency, they couldn’t find it because it comes out in big globs, right, and you say to yourself, ‘How does that help us?’”

Trump is one of the most amusing orators in the history of presidential politics in the the U.S. But I wondered what would happen I took the text of a few of his speeches and fed it into a algorithm that uses Markov chains to shake things up a bit.

A new hexo deployer for Amazon web services

I recently migrated this and my other blog to Hexo which is a very fast static blogging framework built on node.js. As when I used Octopress, this blog is still hosted from an AWS S3 bucket. However the deployers that I tried with Hexo failed because of dependencies that were incompatible with the OS X version I was running. Not being a node.js expert, and having no time to delve into node.js internals, I wrote a new deployer:

Collapsing DEVONthink groups via AppleScript

I’ve been moving to a tag-based system for organizing content in DEVONthink. All of my content for each database goes into a single group called “reference.” If I want to find something, I search the hierarchical tag structure instead of diving into some arbitrary list of groups.

But I still have groups that I’d like to collapse into the reference group. So I wrote an AppleScript to perform this action. Notably, most of the action is in the processGroup() handler which is recursive because we do not know how deep the group hierarchy goes.