Saturday, July 12, 2014

Brotherly Creepfest

Brotherly Creepfest, that would be a great name for a band! But no, Beth, there is no app called "Brotherly Creepfest" At least not yet, there isn't! :-)

Saturday, April 26, 2014

Emacs Window Title

One of those things I'll forget if I don't write it down - how to change the title of an Emacs window.

M-x set-frame-name

th! Stack Overflow

Wednesday, April 23, 2014

New cron job

Welcome to my crontab, new cron job!

18 * * * * ps -feww | grep -v grep | grep python | wc -l | sed -e '/^[0-4]$/ d; s/$/ pythons are running/g'

Why? If you've ever run into the problem where python cron jobs start piling up because of abrtd, and you've restarted abrtd, this will help you keep an eye on things. Every hour on the 18 (so as not to run into one of my running python scripts) I'm counting python processes and if there are more than four, I'll hear about it.

Friday, January 31, 2014

Pet Peeve: "infinite number of"

Welcome to my long list of pet peeves, "infinite number of"!!

Why say "infinite number of monkeys" when you can just say "infinite monkeys"??

Tuesday, January 28, 2014

Solaris TAR with Excluded Directories

It's been a long time since I had to use Solaris, and tar is bad enough without the differences between Linux and my previously favorite Unix!

$ tar cfX - /tmp/excludes . | gzip > ~/excluded.tgz

where /tmp/excludes looks like this:

./sub1
./sub2
./sub3

So it's not just a list of what's excluded, it's starting with the dot!

hattip: thank you, My Couple Of Cents!!

Saturday, November 02, 2013

Android SQLite queries and numeric predicates

The typical code for making an Android SQLite query goes something like this:

Uri uri = MyProvider.URI;
String[] projection = ...;
String where = COLUMN_NAME + "=?";
String[] whereArgs = new String[] { someValue };
String sortOrder = SORT_COL + " " + sortDir;
Cursor c = getContentResolver().query(uri, projection, 
  where, whereArgs, sortOrder);

But what if someValue isn't a String? What if you want to query your database on a numeric column? I was bashing my head against this and getting wrong results until I stumbled onto the suggestion that the "?" argument needs to be converted to a number. How to do it? Just add zero.

long someValue = ...;
Uri uri = MyProvider.URI;
String[] projection = ...;
String where = COLUMN_NAME + "=(?+0)";
String[] whereArgs = new String[] { Long.toString(someValue) };
String sortOrder = SORT_COL + " " + sortDir;
Cursor c = getContentResolver().query(uri, projection, 
  where, whereArgs, sortOrder);

You have to pass your selection arguments as an array of strings, so you'll use toString for that. But the query itself can use an addition operation to convert the string argument to a number. See the "+0" in the where string? That's it.

Maybe there's another, even better way, but this solved my problem - my queries now return just what they're supposed to. All you need is plus.

Tuesday, October 22, 2013

World Series Match-Ups

How many times have the Red Sox and Cardinals played each other in the World Series? This is the fourth time. The others were in 1946, 1967 and 2004. I was alive for two of those - can you guess which ones?

In case you're wondering about other match-ups, here is the complete list of which teams have played each other how many times.

11 Dodgers & Yankees
 7 Giants & Yankees
 5 Cardinals & Yankees
 4 Athletics & Giants
 4 Braves & Yankees
 4 Cubs & Tigers
 3 Cardinals & Red Sox
 3 Cardinals & Tigers
 3 Reds & Yankees
 2 Athletics & Cardinals
 2 Athletics & Cubs
 2 Athletics & Dodgers
 2 Athletics & Reds
 2 Braves & Indians
 2 Cubs & Yankees
 2 Giants & Senators
 2 Orioles & Pirates
 2 Phillies & Yankees
 2 Pirates & Yankees
 1 Americans & Pirates
 1 Angels & Giants
 1 Astros & White Sox
 1 Athletics & Braves
 1 Athletics & Mets
 1 Blue Jays & Braves
 1 Blue Jays & Phillies
 1 Braves & Twins
 1 Brewers & Cardinals
 1 Browns & Cardinals
 1 Cardinals & Rangers
 1 Cardinals & Royals
 1 Cardinals & Twins
 1 Cubs & Red Sox
 1 Cubs & White Sox
 1 Diamondbacks & Yankees
 1 Dodgers & Orioles
 1 Dodgers & Twins
 1 Dodgers & White Sox
 1 Giants & Indians
 1 Giants & Rangers
 1 Giants & Red Sox
 1 Giants & Tigers
 1 Giants & White Sox
 1 Indians & Marlins
 1 Indians & Robins
 1 Marlins & Yankees
 1 Mets & Orioles
 1 Mets & Red Sox
 1 Mets & Yankees
 1 Orioles & Phillies
 1 Orioles & Reds
 1 Padres & Tigers
 1 Padres & Yankees
 1 Phillies & Rays
 1 Phillies & Red Sox
 1 Phillies & Royals
 1 Pirates & Senators
 1 Pirates & Tigers
 1 Red Sox & Reds
 1 Red Sox & Robins
 1 Red Sox & Rockies
 1 Reds & Tigers
 1 Reds & White Sox

Source: Wikipedia, of course! ��