George V. Reilly

Bash: echo success of previous command

C-like languages have a ternary operator, cond ? true_re­sult : false_re­sult. Python has true_re­sult if cond else false_re­sult. Bash doesn’t have a ternary operator, but there are various workarounds.

I wanted to print succeeded or failed based on the exit code of the previous command in a shell script. In Unix, all programs exit with an integer status code. Successful programs exit with 0; all other values, positive or negative, indicate failure. In Bash, the status code of the previous program is held in $?.

some/command or-other fer example

STATUS="$([ "$?" == 0 ] && echo 'succeeded' || echo 'failed')"
echo "Results: $STATUS"

There are other ways to handle this.

Movember 2016

I’ve worn a beard since 1986, when I was 21. Only rarely have I been clean­shaven since then. Emma, who met me in 1997, has only seen me clean­shaven once before, about 15 years ago. I promptly regrew the beard that time.

I decided in October to fundraise for Movember. In truth, I was also curious to see what I looked like without my trademark beard. On Halloween night, I shaved everything off. Interim photos as I whittled down the beard can be seen below, as can some progress photos taken since then as I grew an over-the-top handlebar mustache.

I’ve let the rest of the beard start growing in after my heel operation a week and continue.

Knee Walker

I had heel surgery last week to remove a heel spur which was causing tendonitis and to repair the Achilles tendon. More on that some other time.

I rented a knee walker this morning from Eastside Leg Up. I love it! After barely getting around with crutches for a week, the scooter makes a huge difference. I can move around at normal walking pace now, instead of wearing myself out with the crutches.

In­ci­den­tal­ly, I found my first WebP image in the wild: the original of the image that’s shown here. I used Im­ageMag­ick convert to make it into a JPEG.

Review: The Atrocity Archives

Title: The Atrocity Archives
Author: Charles Stross
Rating: ★ ★ ★ ★
Publisher: Ace
Copyright: 2004
Pages: 345
Keywords: Love­craft­ian spy thriller
Series: Laundry Files, vol. 1
Reading period: 10–12 January, 2017

Bob Howard, Laundry hacker newly promoted to field agent, finds himself protecting a logic professor from rogue SS-Ahnenerbe agents who’ve been hiding in another dimension since the end of the War. But their biggest problem is the frost giant that was summoned. And later there’s the subverted CCTV cameras with the basilisk stare.

To borrow Charlie Stross’s own words from his Crib Sheet:

So there you’ve got the in­gre­di­ents. Love­craft­ian horror; the secret agency [the Laundry] dedicated to protecting us from the scum of the continue.

Git File Modes

Ever wonder what the six-digit file modes are in a Git commit? The mysterious 100644 and 100755 modes?

diff --git a/foo/bar.py b/foo/bar.py
old mode 100644
new mode 100755
index b829edea4..ee6bda024
--- a/foo/bar.py
+++ b/foo/bar.py
@@ -1,3 +1,4 @@
...

I had made foo/bar.py executable by using chmod +x and adding a #!/usr/bin/env python shebang. The last three digits are obviously the same octal digits that you can use with chmod. But what’s that 100 prefix?

The ex­pla­na­tion can be found in a Stack­Over­flow answer:

100644₈  regular file (non-executable)  S_IFREG | S_IRUSR | S_IWUSR
                     
continue.

Review: Boiling Point

Title: Boiling Point
Author: Frank Lean
Rating: ★ ★ ★ ½
Publisher: Arrow
Copyright: 2000
Pages: 432
Keywords: crime, UK
Reading period: 2–5 January, 2017

Dave Cunane is Manchester’s mouthiest PI. He gets tangled up with the wild daughter-in-law of the crooked Carlyle family. Marti wants him to prove the innocence of her father who’s doing life for killing a cop. She doesn’t go over well with Dave’s own half-crazy girlfriend. Neither the Carlyles nor Dave’s ex-police father want Vince King freed. It’s not going to end well.

Computed Parallel Branches in Jenkins Pipeline

I’ve been using Jenkins lately, setting up Pipeline builds. I have mixed feelings about that, but I’m quite liking Groovy.

Here’s an example of a Closure called ac­cep­tance_in­te­gra­tion_tests, where the re­lease_lev­el parameter is a String which must be either "dev" or "prod".

def acceptance_integration_tests = { String release_level ->
    assert release_level =~ /^(dev|prod)$/
    String arg = "--${release_level}"

    def branches = [
        "${release_level}_acceptance_tests": {
            run_tests("ci_acceptance_test", arg, '**/*nosetests.xml')
        },
        
continue.

Review: Death of a Red Heroine

Title: Death of a Red Heroine
Author: Qiu Xiaolong
Rating: ★ ★ ★ ★ ½
Publisher: Soho Crime
Copyright: 2003
Pages: 464
Keywords: crime, China
Reading period: 27 December, 2016–6 January, 2017

Chen Cao is an unlikely new Chief Inspector in the Shanghai Police in 1990, as he’s a poet, a scholar of T.S. Eliot, and a translator of English detective novels. In Death of a Red Heroine, a national model worker has been found murdered in a canal. The death is po­lit­i­cal­ly sensitive and Chen’s in­ves­ti­ga­tion leads him towards the son of a high-ranking cadre, which makes his position even more tenuous.

Qiu is as much concerned with the changes then happening in continue.

Diff a Transformed File

I wanted to diff two files. One of them needed some seds on each line and sorting. I wanted to do that on the fly, without leaving a massaged in­ter­me­di­ate file lying around.

colordiff --unified <(cat orphaned_permalinks.txt
                        | sed 's@http://www.georgevreilly.com/@@'
                        | sed 's/.aspx$/.html/'
                 
continue.

LKRhash: Scalable Hash Tables

LKRhash is a hashtable that scales to multiple processors and to millions of items. LKRhash was invented at Microsoft in 1997 by Per-Åke (Paul) Larson of Microsoft Research and Murali Krishnan and George Reilly of Internet In­for­ma­tion Services. LKRhash has been used in many Microsoft products. The techniques that give LKRhash its per­for­mance include linear hashing, cache-friendly data structures, and fine-grained locking.

If Microsoft had had 20% time, LKRhash would have been my main 20% project. I put a lot of effort into making continue.

Previous » « Next