Month: July 2014

Review: Bodum Insulated Plastic Travel French Press Coffee and Tea Mug

July 29, 2014 Incoherent ramblings , , ,


This product is basically complete crap.  It appears to be made of non-heat resistant plastic, and will crack.

photo 1

In the picture above, the cup is empty, but because of the cracks, coffee cream and sugar has crept into the interior, and is now a very suspicious looking soup of some sort of possibly virulent bacterial soup that can probably leak back out into my coffee if I was to continue using it.

I have had two of these Bodum traveller coffee presses.  The first I bought and it cracked first along the seam above the threads, so that the inside separated from the outside.  I crazy glued it back together, but it then proceeded to get spiderweb like cracks along the base, like so:

photo 2

The second such mug I had was bought for me, since my other one had died.  I’d not have bought a replacement myself, and would recommend to anybody else to stay away from this product entirely.  This second cup never separated at the top, but also cracked along the base and up the sides like the original.

Note that Hudson’s Bay, where both of these products were purchased, no longer carries Bodum products.  Perhaps that was due to poor reviews?

Some Unix command line one liners

July 24, 2014 perl and general scripting hackery , , , , , , , , , ,

Here’s a couple one-liner shell commands collected over the last couple months when it occurred to me to record them.  Each of these I thought were somewhat notable at the time I did so.

Nested “backquotes”

I often have to run commands where it is convenient to have the parameters of the commands in a file.  A simple example is to edit all the files in a list of files, say:

vim `cat c`
# or:
vim $(cat c)

A useful variation of this is to do the same using the output of a command that also takes its input from a file. Here’s one to edit all the “ancestor” files in the version control system, assuming a command vcsancestor that produces such filenames

vim `vcsancestor $(cat c)`
# or
vim $(vcsancestor $(cat c))

Observe how two different methods of embedding shell commands can be combined into one command. In the past I often used for loops for something like this, say:

for i in `cat c` ; do vcsancestor $i ; done > f
vim `cat f`

(because backquotes can’t be nested). It only recently occurred to me that this isn’t a limitation if $() style subshells are used.

Batching commands with xargs

When working in a version control system, it’s often useful to do a batch checkout of all the files that have compilation errors.  Suppose that you made changes that produced the following compilation error output:

$ cat compile.errors
"satauth.C", line 978.30: 1540-0274 (S) The name lookup for "sqlorest" did not find a declaration.
"scrutil.C", line 142.52: 1540-0274 (S) The name lookup for "SQLNLS_SAME_STRING" did not find a declaration.
"testdrv.C", line 1146.16: 1540-0274 (S) The name lookup for "SQLO_OK" did not find a declaration.
"testdrv.C", line 183.15: 1540-0274 (S) The name lookup for "SQLO_OK" did not find a declaration.

Here’s a one liner to checkout all the files in this list of compilation errors (this is AIX xlC error output):

cut -f2 -d'"' x | sort -u | xargs cleartool checkout -nc

The cut command selects just the (first) double-quote delimited text, then dups are removed with sort -u, and finally xargs is used to run a command on each of the files in the resulting output

Looking for a subset of information delimited by markers on separate lines

grep works nicely for matching patterns that are constrained to a single line.  If you are using gnu-grep you can use the -A and -B options to find stuff after and before the pattern of interest.  As an example, in our stacktrace files (a post mortem crash dump format), we have output that includes:


0x00002AAAC74EF263 ossDumpStackTraceInternal(unsigned long, OSSTrapFile&, int, siginfo*, void*, unsigned long, unsigned long) + 0x06e3
0x00002AAAC74EFE89 ossDumpStackTraceV98 + 0x007f
0x00002AAAC74E5C5F OSSTrapFile::dumpEx(unsigned long, int, siginfo*, void*, unsigned long) + 0x04db
0x00002AAABA6EB313 sqlo_trce + 0x0a6f
0x00002AAABA9C52B5 sqloDumpDiagInfoHandler + 0x047b
0x00002AAAAABD5E00 address: 0x00002AAAAABD5E00 ; dladdress: 0x00002AAAAABC8000 ; offset in lib: 0x000000000000DE00 ;
0x00002AAAAABD30A5 pthread_kill + 0x0035
0x00002AAAB5D828DF ossPthreadKill(unsigned long, unsigned int) + 0x0053
0x00002AAABA9C6CA1 sqloDumpEDU + 0x0091
0x00002AAABED7A853 sqlzerdm + 0x149b
0x00002AAAB5D7D745 sqle_remap_errors(int, sqlca*, sqeAgent*) + 0x01c9
0x00002AAAB5DE8717 sqeApplication::AppStopUsing(sqeAgent*, unsigned char, sqlca*) + 0x10b1
0x00002AAAB5D46FF5 address: 0x00002AAAB5D46FF5 ; dladdress: 0x00002AAAAACE1000 ; offset in lib: 0x000000000B065FF5 ;
0x00002AAAB5D4073F address: 0x00002AAAB5D4073F ; dladdress: 0x00002AAAAACE1000 ; offset in lib: 0x000000000B05F73F ;
0x00002AAAB5D44F35 sqleIndCoordProcessRequest(sqeAgent*) + 0x3959
0x00002AAAB5DA8E55 sqeAgent::RunEDU() + 0x061b
0x00002AAABEDAC2C7 sqzEDUObj::EDUDriver() + 0x035d
0x00002AAABEDABBD7 sqlzRunEDU(char*, unsigned int) + 0x0053
0x00002AAABA9BFC62 sqloEDUEntry + 0x1460
0x00002AAAAABCE2A3 address: 0x00002AAAAABCE2A3 ; dladdress: 0x00002AAAAABC8000 ; offset in lib: 0x00000000000062A3 ;
0x00002AAAC7F376DD __clone + 0x006d


Here’s a one-liner to grab just the portions of these files within the delimiters (with some other filtering that isn’t of terrible interest to describe)

for i in *stack* ; do grep -A40 ‘<StackTrace’ $i | grep -v ‘(/’ | grep -B40 ‘/StackTrace’ | c++filt ; done | less

Unix to Windows path separator switching

Suppose we have some unix filenames

$ head -5 f

and want the Windows paths for the same

$ head -5 f | tr / '\\'

The tr command above looks a bit like ascii barf, and will translate forward slashes to backward slashes (perhaps for input that’s a list of files).

I didn’t understand the requirement to both single quote the backslash as well as escaping it, but Darin explained it for me:

Quotes allow the backslashes to go through the shell to tr.  And tr has its own backslash escape mechanism (so you can do things like transform \n into \r or something – where you’d then specify ‘\n’ or just \\n and ‘\r’ or \\r).

Vim: replace search results with contents from a file

Probably related to merging conflicting changes, I wanted to completely replace the implementation of a particular function:

void foo() {

This was an easy way one liner method to do that replacement, deleting the implementation of foo, and replacing it with the one that was found in the file ‘foo’

:,/^}/ !cat foo

file:line: delimited output for a single file

The grep -n command is very handy for producing file:line:content delimited output.  In particular, you can iterate over such output with vim -q.  When you want to do this for a single file, grep -n doesn’t include the filename, defeating a subsequent vim -q (since vim then doesn’t know what file to open).  Here’s an example

$ cat my_file_to_search
blah patternOfInterest hi
foo goo
patternOfInterest bye
blah patternOfInterest hi
blah patternOfInterest hi
foo goo
patternOfInterest bye
foo goo
patternOfInterest bye

$ grep -n patternOfInterest my_file_to_search | tee v
1:blah patternOfInterest hi
3:patternOfInterest bye
4:blah patternOfInterest hi
5:blah patternOfInterest hi
7:patternOfInterest bye
9:patternOfInterest bye

To get vim -q’able output, just include a second non-existent dummy file in the search

grep -n patternOfInterest my_file_to_search a_file_that_doesnt_exist | tee v
vim -q v

I usually use a very-short filename for the “does not exist file”, say, .u (which presumes I also don’t create little hidden files .u in my day-to-day work).

Some initial thoughts on a read of William Blum’s “Rogue State”

July 22, 2014 Incoherent ramblings , , , , , , , , , , , ,

I have started reading the disgusting book “Rogue State, A Guide to the World’s Only Superpower” by William Blum.  It is disgusting not because it is poorly written, but because of the US government, CIA, and military atrocities it details.

It is also a discouraging book, and hard to stomach, and downright depressing.  It is, however, encyclopedic, thorough, and contains extensive references.  If you ever wanted a detailed list of US atrocities to counter arguments that governments, military, and intelligence agencies serve us positively, this book has everything on the shopping list.

There is a huge disparity between popular and media perception of the USA and what is presented in this book.  This disparity brings to mind the paradigm shift discussion of Kuhn’s “Structure of scientific revolutions”.  The perception of the USA (or its NATO and economic puppets like Canada) as freedom loving “democracy” is so indoctrinated into us that to accept the reality that exactly the opposite is true requires a complete paradigm shift.  It is too painful to realize that we have to totally discard our current world view, and be willing to accept the pain and discomfort associated with the mental revolution required to see the actual state of the world.  Kuhn also points out that such a revolution isn’t going to happen until people have a ready made alternative to the current paradigm.  The history of warfare and evil in our world is so pervasive, that I don’t think we have a ready made model of peaceful interaction available for this switch, and are therefore willing to overlook the errors of the current model.  I think that this book details enough of those errors that it puts the current world view on shaky ground.
I find this author to be is an extremely effective communicator.  A sample of his style can be found in this 2002 speech.

The speech above also contains a quote from the intro in “Rogue State” that I found particularly striking:

“If I were the president, I could stop terrorist attacks against the United States in a few days. Permanently. I would first apologize — very publicly and very sincerely — to all the widows and orphans, the tortured and impoverished, and all the many millions of other victims of American imperialism. Then I would announce that America’s global interventions have come to an end and inform Israel that it is no longer the 51st state of the union but -– oddly enough -– a foreign country. I would then reduce the military budget by at least 90% and use the savings to pay reparations to our victims and repair the damage from our bombings. There would be enough money. Do you know what one year’s military budget is equal to? One year. It’s equal to more than $20,000 per hour for every hour since Jesus Christ was born.

That’s what I’d do on my first three days in the White House. On the fourth day, I’d be assassinated.”

Markham bylaws for private property maintainance.

July 16, 2014 Incoherent ramblings , , ,


Markham can fairly oppressive in its bylaw enforcement.  For example, you aren’t allowed to park in front of your house overnight in the Cornell area, where there are cut-in parking spots off the main part of the roadway.  Such a tragic violation of city rules gets you $50 ticket.  There are also maintenance  enforcement officers that will measure the length of your grass and probably ticket you if it is too long.

Because of this enforcement, I was somewhat wary of the idea of creating a front yard vegetable garden.  I know that some cities have cracked down on such a vile practice, so it did not seem implausible that Markham would follow such a police state model of oppressive regulations.

I wrote the following to a Markham representative  to find out what the rules were:

“The sidewalks in my area of Cornell run really close to the house, so that most of the front yard lies in the boulevard area (by which I mean the space between the sidewalk and the road and/or the parking indent).

Most people appear to have left this space with some combinations of weeds and/or grass, sometimes ringing trees or building raised garden boxes.

I see that we have by-law requirements for keeping our property tidy, but don’t know what rules there are for the boulevard area.  Is this considered my space or is it the city’s space, and are there any limits for allowable landscaping and gardening in these spaces? “

I was careful not to give away my intent.  Note that my front yard is one of those with a ‘combination of weeds and grass’.  If I was to pull the weeds, something I tried vainly a couple times, there would be not much left.  I’d love to make that silly grassy weedy space (i.e. the boulevard) into a vegetable garden.

For reference to anybody else who may want to do this, here is the answer I received from the Markham representative:

“Thank you for contacting the City of Markham.

Please follow this link to our Keep Markham Beautiful (Maintenance) By-lawTo regulate and prescribe standards for the maintenance of private property and municipal boulevards within the City of Markham.

Have a look at the by-law and if you have any questions outstanding, please let us know and we will have someone from our By-law staff contact you with more information.

If you find that there are residents in your neighbourhood that are not following the by-law, please let us know and we can start an investigation and educate them on proper maintenance.”

This city representative probably thought that I wanted to rat out some poor neighbour (and included additional information detailing for me how I could go about doing that).  I assume that “educate them” actually means fine them and/or require proof of corrective action.

However, note that the attached document does not appear to prohibit a front yard vegetable garden, even in the boulevard area.  That is at least my interpretation.  I am moving and won’t end up enacting my original idea.  However, I thought that it was worthwhile to share the city response and the bylaw document in case others are thinking of doing something like this (especially in the Cornell area, where back yard space is tiny and all too easy to consume with a very small scale herb and vegetable garden).

Sum of digits of small powers of nine.

July 15, 2014 math and physics play , , , ,

[Click here for a PDF of this post]

In a previous post I wondered how to prove that for integer \(d \in [1,N]\)

((N-1) d) \text{mod} N + ((N-1) d) \text{div} N = N-1.

Here’s a proof in two steps. First for \(N = 10\), and then by search and replace for arbitrary \(N\).

\(N = 10\)


x = 9 d = 10 a + b,

where \(1 \le a, b < 9\), and let \begin{equation}\label{eqn:numberGame:180} y = a + b, \end{equation} the sum of the digits in a base \(10\) numeral system. We wish to solve the following integer system of equations \begin{equation}\label{eqn:numberGame:60} \begin{aligned} 9 d &= 10 a + b \\ y &= a + b \\ \end{aligned}. \end{equation} Scaling and subtracting we have \begin{equation}\label{eqn:numberGame:80} 10 y - 9 d = 9 b, \end{equation} or \begin{equation}\label{eqn:numberGame:100} y = \frac{9}{10} \lr{ b + d }. \end{equation} Because \(y\) is an integer, we have to conclude that \(b + d\) is a power of \(10\), and \(b + d \ge 10\). Because we have a constraint on the maximum value of this sum \begin{equation}\label{eqn:numberGame:120} b + d \le 2 ( 9 ), \end{equation} we can only conclude that \begin{equation}\label{eqn:numberGame:140} b + d = 10. \end{equation} or \begin{equation}\label{eqn:numberGame:160} \boxed{ b = 10 - d. } \end{equation} Back substitution into \ref{eqn:numberGame:40} we have \begin{equation}\label{eqn:numberGame:200} \begin{aligned} 10 a &= 9 d - b \\ &= 9 d - 10 + d \\ &= 10 d - 10 \\ &= 10 \lr{ d - 1 }, \end{aligned} \end{equation} or \begin{equation}\label{eqn:numberGame:220} \boxed{ a = d - 1. } \end{equation} Summing \ref{eqn:numberGame:220} and \ref{eqn:numberGame:160}, the sum of digits is \begin{equation}\label{eqn:numberGame:240} a + b = d - 1 + 10 - d = 9. \end{equation}

For arbitrary \(N\)

There was really nothing special about \(9, 10\) in the above proof, so generalizing requires nothing more than some search and replace. I used the following vim commands for this “proof generalization”

:,/For arb/-1 y
:+/For arb/+1
:,$ s/\<9\>/(N-1)/cg
:,$ s/\<10\>/N/cg
:,$ s/numberGame:/&2:/g


x = (N-1) d = N a + b,

where \(1 \le a, b < N-1\), and let \begin{equation}\label{eqn:numberGame:2:180} y = a + b, \end{equation} the sum of the digits in a base \(N\) numeral system. We wish to solve the following integer system of equations \begin{equation}\label{eqn:numberGame:2:60} \begin{aligned} (N-1) d &= N a + b \\ y &= a + b \\ \end{aligned}. \end{equation} Scaling and subtracting we have \begin{equation}\label{eqn:numberGame:2:80} N y - (N-1) d = (N-1) b, \end{equation} or \begin{equation}\label{eqn:numberGame:2:100} y = \frac{N-1}{N} \lr{ b + d }. \end{equation} Because \(y\) is an integer, we have to conclude that \(b + d\) is a power of \(N\), and \(b + d \ge N\). Because we have a constraint on the maximum value of this sum \begin{equation}\label{eqn:numberGame:2:120} b + d \le 2 ( N-1 ), \end{equation} we can only conclude that \begin{equation}\label{eqn:numberGame:2:140} b + d = N. \end{equation} or \begin{equation}\label{eqn:numberGame:2:160} \boxed{ b = N - d. } \end{equation} Back substitution into \ref{eqn:numberGame:2:40} we have \begin{equation}\label{eqn:numberGame:2:200} \begin{aligned} N a &= (N-1) d - b \\ &= (N-1) d - N + d \\ &= N d - N \\ &= N \lr{ d - 1 }, \end{aligned} \end{equation} or \begin{equation}\label{eqn:numberGame:2:220} \boxed{ a = d - 1. } \end{equation} Summing \ref{eqn:numberGame:2:220} and \ref{eqn:numberGame:2:160}, the sum of digits is \begin{equation}\label{eqn:numberGame:2:260} a + b = d - 1 + N - d = N-1. \end{equation} This completes the proof of \ref{eqn:numberGame:20}.