Northward Midget Pole to Pole


Shell Nuggets: Quickie Tabulizer

Posted by Quinn

I'm real bad about things lining up.  Used to go out of my way to ensure variable declarations were columnized by access mode, type, name, equals sign and initial value.

final BufferedImage mapImg = MapImageFactory.newInstance(width, height);
final int           count  = ad.getPosition() * 2;

mapImg.composite(adImg, 25               , (this.adHeight + 20) * count + 20, Over);
mapImg.composite(adTxt, 25 + this.adWidth, (this.adHeight + 20) * count + 20, Over);

The Tabularizer plugin for vim was a boon for productivity.  Well, mine.  For everyone else, it meant either destroying the pre-formatted beauty or re-aligning all the columns.

Anyway, it's considered bad practice, so I've tried to get away from it-- at least when writing shared code.  I still like perfect tabular output in my day-to-day.  Take the df command, for example.  It's default "human readable sizes" output:

2016-02-05 11:03:57 «««« ~
 rons@rons-VM$ df -h
Filesystem            Size  Used Avail Use% Mounted on
                       59G   29G   27G  52% /
/dev/sda1              99M   33M   61M  36% /boot
tmpfs                 1.5G     0  1.5G   0% /dev/shm

Bleah. A line break. Why you mess my rows, GNU? An easy fix jumped into my noggin the other day and crept down my arms and out my fingertips:

2016-02-05 11:03:58 «««« ~
 rons@rons-VM$ df -h | sed 's/Mounted on$/Mount/;' | xargs printf '%-40.40s %8s %8s %8s %5s  %s\n'
Filesystem                                   Size     Used    Avail  Use%  Mount
/dev/mapper/VolGroup00-LogVol00               59G      29G      27G   52%  /
/dev/sda1                                     99M      33M      61M   36%  /boot
tmpfs                                        1.5G        0     1.5G    0%  /dev/shm

The trick is that a printf format with a trailing newline will repeat if it runs out of input tokens.   That's why I had to truncate the "Mounted on" to just "Mount" above-- otherwise there would be an irregular number of columns (and thus printf tokens) on each line/row.  Spaces in filesystems and mounts will mess it up, too, but if you use spaces in the names of your mounts, you deserve the dissonance.

Edit: Better shell function replacement below.

unset -f df ; function df() {
  command df -P $@ | perl -ane '
    push(@rows, [@F]);
    for (0..$#F) {
      $ll = length($F[$_]); $cm[$_] = $ll if $ll > ($cm[$_] // 0);
    END { printf("%-$cm[0]s %$cm[1]s %$cm[2]s %$cm[3]s %$cm[4]s %s\n", @{$_})
      for @rows; }';
} ;


Uses the -P flag for POSIX one-line-per-mount format.   Dynamically calculates column widths.


Tagged as: , No Comments

G+ Repost: Disney v. Lucasfilm

Posted by Quinn

Beginning a series of copy-pastes of my comments posted on Google+, since few people read G+, and the comments are usually buried so deep that even fewer people will read them, and the ones I pick are usually worth a wider audience.  Like  Yeah.  I probably have a larger audience than Google's social network.  SHUT UP SHUT UP SHUT UP.

Anyhoo, this was one of those flash-polls on the Star Wars group.  Two buttons with two logos: Disney and Lucasfilm Ltd.  Of course, 90% of respondents are Lucas fanfilk{sic} with no cognisance of movie history.  So, after reading too many comments containing "not even in the same league", I click Disney and opine:

No, they're not in the same league. Disney revolutionized and popularized animation as an art form. Lucas was at the right place at the right time with a few reels of Kurosawa and a worn copy of "The Power of Myth".

Disney also owns companies that have produced some of the greatest films of the past century that have nothing to do with princesses and anthropomorphized fauna.

Full credit to Lucasfilm for all they've accomplished (that I've omitted), but they really can't compare to Disney-- not even purely on the basis of an art-to-shit ratio. I'm glad Disney is now at the helm of Star Wars, and that Lucas is where he belongs-- navigating in the map room.



Protected: The Coward’s Price For Sobriety

Posted by Quinn

This content is password protected. To view it please enter your password below: