George V. Reilly

Python Print Formatting

On Stack­Over­flow, someone wanted to print triangles in Python in an M-shape. Various clumsy solutions were offered.

Here’s mine which uses the left- and right-jus­ti­fi­ca­tion features of str.format.

Putting them together:

.. code:: pycon
>>> WIDTH = 4
>>>
>>> for a in range(1, WIDTH+1):
...     print("{0:<{1}}{0:>{1}}".format('*' * a, WIDTH))
...
*      *
**    **
***  
continue.

Review: Star Fall

Title: Star Fall
Author: Cynthia Harrod-Eagles
Rating: ★ ★ ★ ★
Publisher: Severn House
Copyright: 2015
Pages: 256
Keywords: mystery, police procedural
Reading period: Nov 28–Dec 3, 2015

Rowland Egerton, star of a popular antiques TV show, is found murdered in his London home. When Detective Inspector Bill Slider and his team in­ves­ti­gate, they uncover sordid secrets unknown to the British public.

This was a witty and en­ter­tain­ing police procedural, showing both the working and home lives of Slider and team.

Review: Grace of Kings

Title: Grace of Kings
Author: Ken Liu
Rating: ★ ★ ★ ★
Publisher: Saga Press
Copyright: 2015
Pages: 614
Keywords: fantasy
Reading period: Oct 1–Dec 2, 2015

Loosely modeled on the rise of the Han dynasty, Ken Liu’s fantasy tells us of two men who rise up to challenge the emperor. Kuni Garu, the wily and wise one-time bandit, and Mata Zyndu, the warrior scion of a deposed noble clan, are friends initially but fall out. The gods are at play in the affairs of men and they take pleasure in causing trouble and strife.

I enjoyed the novel, but I disliked the pace at which Liu galloped through events.

More

Microsoft Natural Keyboard 4000 on Mac OS X 10.11: Alt/Windows key no longer swapped

When I upgraded my home and work MacBooks to OS X 10.11 (El Capitan), the single biggest annoyance for me was that my external keyboards, all Microsoft Natural Keyboard 4000s, no longer swapped the Alt & Windows key.

By default, when a PC keyboard is plugged into a Mac, the Alt key, which is im­me­di­ate­ly to the left of the spacebar, is mapped to the Alt/Option key, which is two keys left of the spacebar on a Mac keyboard. And the Windows key, which is two keys to the left of the spacebar on a PC keyboard, is mapped to the Command key, which is next to the spacebar on a Mac keyboard.

On a Mac, continue.

Explaining the epilog of fnmatch.translate, \Z(?ms)

I was debugging a filtering directory walker (on which, more to follow) and I was trying to figure out the mysterious suffix that fnmatch.translate appends to its result, \Z(?ms).

fnmatch.translate takes a Unix-style glob, like *.py or test_*.py[cod], and translates it character-by-character into a regular expression. It then appends \Z(?ms). Hence the latter glob becomes r'test\_.*\.py[cod]\Z(?ms)', using Python’s raw string notation to avoid the backslash plague. Also, the ? wildcard character becomes the . regex special character, while the * wildcard becomes the .* greedy regex.

A Stack­Over­flow answer partially explains, which set me on the right track. (?ms) is equivalent to compiling the regex with re.MULTILINE | re.DOTALL. The re.DOTALL modifier makes the . special character match any character, including newline; normally, continue.

On Blogging

Blogging has been on my mind lately, as I’ve just set up an en­gi­neer­ing blog at work.

I gave a speech about blogging earlier tonight to my club, Freely Speaking Toast­mas­ters. I no longer write speeches be­fore­hand; I ex­tem­po­rized my speech from a mindmap that I had prepared yesterday. This post is a more coherent and expanded rendition of my points.

As Toast­mas­ters, we give speeches about topics that interest us, when we want to share or inform or entertain. A live, in-person speech reaches a direct audience at one point in time. A written blog post can reach a much larger audience. Toast­mas­ters have something to say, whether in person or in print.

A blog can continue.

Setting Up a Pairing Workstation for Chrome and Git

[Pre­vi­ous­ly published at the now defunct MetaBrite Dev Blog.]

At MetaBrite, we believe in the power of pair pro­gram­ming. We find that pairing helps for col­lab­o­ra­tion on difficult tasks, for exploring new areas, for knowledge transfer, and for spurring each other to better solutions. I find it to be fun, though it can also be exhausting. It’s not ideal for all our work—there’s no value in tying up two developers on some rote task that both know well.

Last week, I rebuilt our primary pairing work­sta­tion. In its previous in­car­na­tion, we had an account for each developer. Each of us had set up some personal pref­er­ences in our own user continue.

RunSnakeRun (wxPython) apps in a Brew Virtualenv

I’m doing some Python profiling and I wanted to use the Run­SnakeRun utility to view the profile data. Un­for­tu­nate­ly, that’s not straight­for­ward on Mac OS X if you use a virtualenv, and it’s even less easy if you’re using the Python installed by the Homebrew (brew) package manager.

There are several problems:

Installing wxPython

I downloaded wxPython3.0-osx-3.0.2.0-cocoa-py2.7.dmg, released in November 2014.

If you open the DMG and attempt to run the PKG, you will likely get a misleading error message from OS X:

“wxPython3.0-osx-cocoa-py2.7.pkg” is damaged and can’t be opened. You should eject continue.

Review: Hard Freeze

Title: Hard Freeze
Author: Dan Simmons
Rating: ★ ★ ★ ★
Publisher: St. Martin’s/Minotaur
Copyright: 2002
Pages: 295
Keywords: crime, thriller, noir
Reading period: 27 May, 2015

Joe Kurtz is marked for death after the events of Hardcase. And a concert violinist is convinced that he just saw the man who murdered his teenaged daughter 20 years earlier, who was thought dead. More mayhem.

Off to Berlin: Spring Cleaning

As I announced a couple of weeks ago, we’re off to Berlin for June and July. We leave the house at 4:30am tomorrow to catch a 6:45am flight to Chicago and thence via Dublin, arriving in Berlin at 10:30am on Tuesday.

There’s nothing like a deadline to focus the mind and make things happen. We’ve been spring cleaning furiously for several weeks. Frankly, it was long overdue. The bedrooms and the offices were all badly in need of being re­or­ga­nized. My office used to scare me, it was such a mess. It’s still far from perfect, but it’s much cleaner, you can use the desk, and the remaining clutter is stacked into continue.

Previous » « Next