George V. Reilly

SQLAlchemy got me Killed

I ran a script this afternoon that died mys­te­ri­ous­ly without any output. It was using SQLAlchemy to query all the rows from a large table so that they could be trans­formed into JSON Lines to be loaded into Elas­tic­search. When I reran my script, I noticed this time that something had printed Killed at the very end.

A little research convinced me that the OOM Killer was the likely assassin. I looked in /var/log/kern.log and I found that my process had used up almost all of the 8GB on this system before being killed.

The query had to be the problem. A little more research led me to augment my query with continue.

Disabling Vibrating Notifications in the Facebook Android App

I’ve had to figure this out twice in recent months, and it was no easier the second time than the first.

If you reinstall the Facebook app on Android, you will be plagued by the phone buzzing every few minutes to notify you that someone posted something.

The relevant setting is buried deeply.

Python: Joining URLs with posixpath.join

On Mac/Linux, os.path.join is an alias for posixpath.join, which always joins path segments with /. On Windows, os.path.join is an alias for ntpath.join, which always uses \. When dealing with URLs, we always want forward slashes, regardless of platform, so posixpath.join should be used to build URL paths.


from __future__ import print_function

from six.moves.urllib_parse import urljoin as abs_urljoin
from posixpath import join as path_urljoin

def urljoin(site, path):
    return abs_urljoin(site, path)

def test_join(site, path):
    result = urljoin(site, path)
    print("'{0}' + '{1}'\n\t-> '{2}'".format(site, path, result))
    return result

local_path = path_urljoin('2016', '07', '12', 'release', 'index.html')

test_join('', 'foo/bar/quux.js')
test_join('', local_path)
test_join('', local_path)
test_join('', local_path)


'' + 'foo/bar/quux.js'

Logging in Python: Don't use new-fangled format

Python 2.6 introduced the format method to strings. In general, format is now the preferred way to build strings instead of the old % formatting operator.

One exception is with the logging module, where the best practice is to use %s and %d. Why? First, %s is the idiomatic way to use logging, which was built years before format was introduced. Second, if there’s a literal % in the in­ter­po­lat­ed values, logging will be unhappy, since there won’t be cor­re­spond­ing arguments in the call. It won’t fall over, since “The logging package is designed to swallow exceptions which occur while logging in production. This is so that errors which occur while handling logging events - continue.

Review: Flashman and the Mountain of Light

Title: Flashman and the Mountain of Light
Author: George MacDonald Fraser
Rating: ★ ★ ★ ★
Publisher: Plume
Copyright: 1990
Pages: 368
Keywords: historical fiction, humor
Reading period: 29 June–10 July, 2016
Flashman Papers IX: 1845–46

Flashman and the Mountain of Light takes place just after Flashman’s Lady, and it also falls between the two parts of Royal Flash, making it the fourth book chrono­log­i­cal­ly of the Flashman Papers and the ninth book published.

In the prologue, our hero finds himself telling Queen Victoria a much-edited version of how he came to acquire the Koh-i-Noor diamond on the crown’s behalf forty years earlier during the First Anglo-Sikh War. The actual story—at least according to Flashman and Fraser—is that continue.

Black Lives Matter: Alton, Philando, and Dallas

What an awful week for race relations in the United States of America. On Monday night, Alton Sterling was shot and killed by Baton Rouge police. One night later, Philando Castile was shot and killed by police in Minnesota. Both men were black and neither was resisting arrest. Both shootings were caught on video, which inflamed passions. On Thursday night at a peaceful rally in Dallas protesting police violence, two snipers killed five police officers and wounded seven others. Micah Johnson was later killed by police in a standoff; three others were arrested.

The police should not have killed Alton Sterling or Philando Castile—or Tamir Rice or Freddie Gray or continue.

Teatro Zinzanni

Teatro Zinzanni is a long-running circus dinner theater in Seattle. Six of us went tonight and enjoyed a blend of cabaret, circus arts, fine dining, and vaudeville.

The current show, Hotel L’Amour, is ostensibly set in a fine hotel, where the oc­to­ge­nar­i­an Madame reminisces about her career, while Caesar the lounge lizard hams it up, Maestro Voronin brings a puppet girl to life, one aerialist cavorts around an enormous martini glass, a juggler dazzles with his ver­sa­til­i­ty, another aerialist works the straps, and the soprano trills. All this while the audience eats a fairly decent meal spread out over three hours.

‘Twas enjoyable to be sure and the acts were good but it was hard continue.

Review: The Tailor of Panama

Title: The Tailor of Panama
Director: John Boorman
Rating: ★ ★ ★ ★
Released: 2001
Keywords: spy thriller, satire
Watched: 7 July, 2016

Andy Osnard (Pierce Brosnan) is a disgraced MI6 officer, packed off to Panama, where he recruits Harry Pendel (Geoffrey Rush), the eponymous tailor. Osnard is an un­scrupu­lous dirtbag; Pendel is a fabulist in need of money; they’re made for each other. Panama is “Casablan­ca without the heroes” and Pendel spins tall tales that make their way back to London. Eventually, he outdoes himself, claiming that the Canal is to be sold to the Chinese. Osnard manages to procure $15 million to fund a revolution, which he plans to abscond with.

Brosnan plays against type continue.

Bash: Bulk Renaming

I had to rename several hundred thousand files today. Thanks to a botched invocation of Im­ageMag­ick, they all looked like unique_pre­fix.png.jpg, whereas we simply wanted unique_pre­fix.jpg.

I found a suitable answer at the Unix Stack­Ex­change. As one of the many variants of parameter sub­sti­tu­tion, Bash supports ${var/Pattern/Re­place­men­t}: “first match of Pattern within var replaced with Re­place­ment.”

for f in *.png.jpg;
    mv $f "${f/.png}"

The target expression could also have been written as "${f/.png.jpg/.jpg}"

Review: Flashman's Lady

Title: Flashman’s Lady
Author: George MacDonald Fraser
Rating: ★ ★ ★ ★
Publisher: Plume
Copyright: 1977
Pages: 330
Keywords: historical fiction, humor
Reading period: 24–29 June, 2016
Flashman Papers VI: 1842–45

Flashman’s Lady takes place between the two parts of Royal Flash, making it the third book chrono­log­i­cal­ly of the Flashman Papers and the sixth book published.

Flashman and his wife, Elspeth, become friendly with Don Solomon Haslam, a rich merchant from the East Indies. Losing a wager to Haslam, who is smitten with Elspeth, Flashy has to let Haslam take Elspeth and her father on a trip to Singapore. As things have become hot for him in England, he sails east with them. Haslam’s feelings for continue.

Previous » « Next