Clearing the Baffles (II)

Three months ago, I "cleared the blogging baffles" and actually found it fairly cathartic. Based on that, I set up a task reminder to remind me to do just that every three months on the 20th.

Here are the posts sitting in my drafts folder that I'll likely never get to finishing / cleaning / etc.:

  • Email Link at Right (tags: how-to )
  • 5 Geek Decisions I Wish I’d Made Differently (tags: uncategorized )

delete

May 20th, 2008

Prime Time

Every so often I go back through posts on my old blog, which is securely archived for my own random access.1 I read one the other day that made me chuckle with geekish delight as I read:

1,000,003 is the smallest seven-digit prime number I could think of, which, being completely impossible to wholly divide from, should take care of the repetitive quotes.

Backstory: I used to have a random quote generator made up of stupid phrases I'd collected over time. Some were output from fortune, some from movies or tv shows, and others were stupid inside jokes. There were far too many Family Guy references, IIRC. It played well to the quasi-personal, friends-oriented content I was producing at the time. Each quote was an entry in a MySQL table with a primary key which I used for retrieval based on this code:

1
2
3
4
5
srand((double)microtime()*1000000);
$tq\_query = mysql\_query("select count(qid) from quotes") or die ('Invalid Query: ' . mysql_error());
$getQuote = sprintf("select quote from quotes where qid='%s';", addslashes(rand(1, mysql\_result($tq\_query,0)-1)));
$gq\_result = mysql\_query($getQuote) or die ('Invalid Query: ' . mysql_error());
echo mysql\_result($gq\_result,0);

Aside: As I copy and paste this now, I wonder why I didn't just do something like "SELECT quote FROM quotes ORDER BY rand() LIMIT 1", putting the responsibility for randomness on MySQL's already set up random seed? I may have been over-prioritizing database robustness on a site that never got more than a few hundred hits per day.

My girlfriend at the time (now my wife) noticed that the quotes didn't actually seem that random and, in fact, the same few kept repeating themselves over and over again. I had noticed the same thing, but never felt that motivated to investigate.2

After reading a bunch of threads on the PHP website, I reasoned that the problem was that I was seeding the random stack with an even number. Due to silly rounding and a padding value, the number most commonly returned out of this function was 24, which is incredibly un-prime. [Even cooler to the numbers nerd inside of me, 24 is the largest number divisible by all numbers less than its square root.] So.. following good number theory, I changed the seed value to 1000003, which is prime, and in few other ways special.

In additional retrospect, saying "that I could think of" was quite silly… The list of smallest n-digit primes is readily available, so this shouldn't require much thought at all. If memory serves, I don't believe I looked this up, and really, how hard should it be for someone who finds math fun to know that 100001 and 100002 aren't prime (11 and 2 are lowest divisors, respectively)?


  1. There are some fairly good posts on it about technology that wouldn’t make sense to re-post here, but are still a good reference for me.

  2. She was, I think, between classes and it bothered her… so who am I to argue?

May 19th, 2008

Cygwin Prompt Here for tcsh

In a post I can no longer find, Scott Hanselman blogged about a registry entry to add a "Command Prompt Here" item to Windows' right-click context menu. This has, many times, saved me almost 30 seconds of opening cmd.exe and typing out a ridiculous CD statement. Since then, however, I've found myself using Cygwin a lot more than cmd as it gives me a lot more power in an environment with which I'm much more familiar.1

Because of my Cygwin-love, I've found myself using the Command Prompt Here context-menu item, and then immediately entering tcsh and doing what needs to be done. I can', then, double Ctrl-D my way out of the window since cmd has no clue what Ctrl-D is. It's annoying, but it means I have to take the extra two seconds to type 'exit'. So, throwing any concept of cost/benefit out the window [though, those four seconds probably add up to like... 30 minutes of lost productivity a year], I investigated how to do the same thing for Cygwin.

Somebody figured this out already, so all that was left was for me to have it run tcsh instead of bash, and I was all set. This was painfully simple. Here's the registry script I'm using:

1
2
3
4
5
6
7
8
9
10
11
12
REGEDIT4
[HKEY_CLASSES_ROOT\Directory\shell\TcshHere]
@="&Cygwin Prompt Here"

[HKEY_CLASSES_ROOT\Directory\shell\TcshHere\command]
@="c:\cygwin\bin\bash.exe --login -c \"cd '%1' ; exec /bin/tcsh\""

[HKEY_CLASSES_ROOT\Drive\shell\TcshHere]
@="&Cygwin Prompt Here"

[HKEY_CLASSES_ROOT\Drive\shell\TcshHere\command]
@="c:\cygwin\bin\bash.exe --login -c \"cd '%1' ; exec /bin/tcsh\""

  1. Some things are kinda wonky (pathnames, for instance) but it’s more user-friendly to me, and I can’t quite get into PowerShell like some of my more Windows-oriented friends.

The Dark Side

Heh.

Apr 30th, 2008

Command Line Upgrade to 8.04 Hardy Heron

Ubuntu 8.04 is the second LTS release of the incredibly popular Linux distro. Inspired, I did a fresh install of my desktop at work and found the process smooth and about as simple as an XP install1, and am quite happy with the results.

Then, I thought it might be fun to see if my svn box in the basement would survive a command-line upgrade again (it worked for 7.04 to 7.10), so why not? The process is fairly straightforward. As root (or via sudo):

  1. sed -e 's/gutsy/hardy/g' -i /etc/apt/sources.list
  2. apt-get update
  3. apt-get dist-upgrade
  4. ... wait ...
  5. shutdown -r now

During my install this morning, and the corresponding install of several packages not included by default, I found that the default repository [us.archive.ubuntu.com] is really slow right now. Synaptic Package Manager has this nifty "find the best mirror" tool, and lo and behold, the best option for me is in Switzerland [mirror.switch.ch], so rather than just replace 'gutsy' with 'hardy', I updated my sources.list to match the fresh one at work.

Then I saw this:

947 upgraded, 194 newly installed, 67 to remove and 0 not upgraded. Need to get 763MB of archives. After unpacking 473MB of additional disk space will be used. Do you want to continue [Y/n]?

Well, yeah, of course... but wow, that's some update! Undaunted, I pressed on. Sure enough, it really was that simple. The upgrade on my Dual-PIII 667 (yeah, that's right, PIII baby!) workstation took just over 4 hours to complete, according to my history, so not too shabby.

Grab ubuntu 8.04 directly from the ubuntu.com web site, or from one of many mirrors.


  1. Admittedly about 10 minutes faster!

Apr 25th, 2008

Reading The News With Little Time

Keeping up with the goings-on in the world seems to be harder than normal these days. Maybe it's life and maybe it's work, but it seems like I have less and less Quadrant 2 and 4 time lately.1 One of those low-priority things I enjoy doing is reading posts from all around the blogosphere and for a few years, I've used a feed reader to centralize all of that reading.

For your money2, there are few better products than those from NewsGator. Both FeedDemon [Windows] and NetNewsWire [MacOS] are excellent readers, and if you happen to read in multiple locations, you have ability to sync your feeds and clippings folders, keeping yourself from re-reading everything. For sure, web-based readers work well for this also3 and many folks also like to use Google Reader and Bloglines.

Retaining a high level of personal productivity whilst reading ~200 RSS feeds is nearly impossible, however. To stay on top of the news and not waste both time and focus, I rely heavily on clippings folders within FeedDemon. I don't find them all that useful when I'm at home using NetNewsWire, but at work they're crucial.

My tactic is to take about 15 minutes when I get to work to go through the overnight news feeds. [This is generally the same time that I'm also whittling down my Inbox, making sure I know my tasks for the day and so forth, so it's a good time to process everything I've collected before getting started with my day.] I have six clippings folders so that I can properly prioritize my reading later in the day:

  • blog: Posts about which I'd like to post, not items I want to link to
  • do - next 10 days: Reminding me to do something or install something soon
  • do - next 6 weeks: Reminding me to do something or install something in the near future, but not right away (e.g. I know I want to split up this huge DJ Tiësto concert track, but know I don't have time right now, so the link reminding me how to do this in iTunes would sit here.)
  • do - someday: Reminding me to do something or install something, but I know I can't any time soon (e.g. if I know I want to put non-standard firmware on my wireless router, but not until after I switch ISPs, and I know that's 1-2 months away, I would put that post here.)
  • read: Default folder for posts I should read
  • tag: Items I want to tag on del.icio.us for future, long-term reference
  • watch or listen: Basically the same as "read", except that I'll need headphones.

I'd say I come in to anywhere between 100 and 400 posts to filter through in a morning, (most of which are from the digg.com feed. I can knock them out easily in those 15 minutes by refraining from reading anything substantively, reading the title and skimming the post body to see if it might be worth my time later. This works pretty well as I'll end up with about 30-50 new posts to read/watch, some of which will migrate to the one of the do/blog clippings folders at some point.

Next, of course, is actually reading said news.

On days not like today, I tend to read through the "read" stack on my lunch break [I had a conference call today, so... bad example] or when I need a mental break between particularly intense tasks or meetings. I make a consistent habit of closing NewsGator right after my morning feed processing4 so as not to be tempted to start the day on an unfocused foot. All of my feeds and clippings sort in reverse chronological order so that I don't lose track of things I wanted to read last week (the week before... month before... year before...) I find that lunch is also a good time to watch whatever posts included video, which mostly consist of clips from The Daily Show and other commentary.

Not sneaking feed views throughout the day takes a level of distraction-relevant self-control that I have not always had. It's very important, however, to maintain a professional level of focus without killing ones's self. For reading the news, this means that I only read what's important, and that do not waste much, if any, time in the office. I had thought that by only giving myself a set amount of time to read, I'd never get caught up, but that screen grab above shows only a half-dozen items in my "read" folder. It's never quite empty, and only a few times (e.g. after vacation or a long weekend) has it stayed above 20 for long periods of time.

The downside is, of course, that if my daily habit is to read at lunch then this means I'm sitting at my desk instead of socializing or being outside. In the winter, or on meeting-heavy days when I need a moment away from people, this isn't a big deal... but it's Spring, so now I find myself taking a walk at lunch instead, and leaving my reading for another day. All of those posts are retained in the client (even if the blog goes poof, they're still there), so I can come back and read them on rainy or cold day instead.

All in all, this method keeps me on top of the news, and also on top of my work, which is the point to the exercise of adding more stuff whilst retaining productivity.


  1. I’m not complaining… sometimes one needs an adrenaline rush!

  2. technically none

  3. FeedDemon has an online reader which also synchronizes with the other clients

  4. NOT a farming term, mind you

Newseum: Today's Front Pages

The other day, I caught a post on Signal Vs. Noise about using Automator in OS X to grab your favorite newspaper's front pages from Newseum as PDFs and join them. This sounded like a great idea, so I set out to do just that.

Unfortunately for me, this particular workflow only works in OS X 10.5, and I have yet to upgrade my iMac past 10.4.11.

Undaunted, I replicated the same thing in perl. It turns out that the "Combine PDF Pages" automator action is a simple Python script. It looked semi-useful on its own, so I copied it from its normal home (/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/) to my personal bin directory for good measure. Perl source follows... please note that the >'s are rendering as literal >'s. Silly Code Highlighter!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#! /usr/bin/perl -w

use locale;
use strict;
use warnings;

#############################
#  [01-31]      [yyyy-mm-dd]
my ($day,       $date,      $tmpdir,              $tojoin) =
(`date +%d`, `date +%F`, '/Users/shelton/tmp', '');
chomp($day); chomp($date);

my ($join) =
("python /Users/shelton/bin/join.py -o '/Users/shelton/Desktop/$date.pdf'");

########################
# Define PDF Links Here
#
my (%papers) = (
# Boston Globe
0=>"http://www.newseum.org/media/dfp/pdf$day/MA_BG.pdf",
# Chicago Tribune
1=>"http://www.newseum.org/media/dfp/pdf$day/IL_CT.pdf",
# Buffalo News
2=>"http://www.newseum.org/media/dfp/pdf$day/NY_BN.pdf",
# NY Times
3=>"http://www.newseum.org/media/dfp/pdf$day/NY_NYT.pdf",
# Wall Street Journal
4=>"http://www.newseum.org/media/dfp/pdf$day/WSJ.pdf"
);

######################################
# Loop through %papers
#  -> Determine tmp output file
#  -> Download the File
#  -> Add file to string for join cmd
#
foreach my $page (sort(keys %papers)) {
my $output = "" . $tmpdir . "/" . $page . ".pdf";
`wget -q -O $output $papers{$page}`;
$tojoin .= "'" . $output . "' ";
}

##################
# Join The Files!
#
`$join $tojoin`;

#############################
# Delete All Downloaded PDFs
#
foreach my $file (sort(keys %papers)) {
my $rm = "" . $tmpdir . "/" . $file . ".pdf";
`rm -f $rm`;
}

I suppose I could have picked more interesting papers (like, for instance, the Amazônia Hoje from Belém, Brazil). I stuck to papers from my current and previous home towns (and the NYC area, because they have interesting papers). Boring? I know...

I run this daily from cron at about 7am. Of note, I also redirect all output of the script to /dev/null because the python script throws a ton of meaningless errors that don't mar the output.

Apr 20th, 2008

Wordpress 2.5

The Wordpress upgrade guide says:

Consider rewarding yourself with a blog post about the upgrade, reading that book or article you've been putting off, or simply sitting back for a few moments and let the world pass you by.

So, a post, then. I must say that the interface is going to take a bit of getting used to. In addition, the color scheme choices are... kinda muted. I liked the darker blue from previous 2.x versions, and high glare situations, I'm noticing that I can't always see the logical separation of the menu section.

Oh hey! I can switch back the old color scheme! Excellent.

The UI changes made to the post editor are excellent. I like the understated "Add media" buttons, and the additional AJAX functionality is useful and not overbearing, exactly how said technology should be used. The UI and font selections system-wide are great.

I don't like that they still haven't fixed the DST time zone thing.

Beyond that, not bad. The upgrade process went smoothly, and here I am.

Apr 19th, 2008

April 1st

I don't get into April Fool's Day. I think my nefarious side went to sleep somewhere around the time just after I saran wrapped my 12th grade area office (VP, class counselor, etc.). Since then, I can't seem to come up with good, mysterious, (harmless) and intelligent pranks. So I just don't bother.

I do, however, get a real kick out of what folks on the internets come up with.

For instance, QWANTZ (Dinosaur Comics), XKCD and Questionable Content are all currently redirecting their current comics' pages to each others' sites in a revolving "OMG WHAT HAPPEND TO TEH WORLDZ!!" sort of way that makes you seriously wonder "Did I click on the right link?".

ThinkGeek, who has done does this every year since 2001, has come up with an excellent set of not-actually-real-but-you-want-them-to-be-real goods for your perusal. I'm digging the Defendius Labyrinth Security Lock, myself.

Last year, they featured an 8-bit tie which was so popular, they actually made one.

Slashdot usually posts some funny, totally untrue, stories. I'm not saying they necessarily forgot it was April 1st, but they do seem to be taking their sweet time.

Apr 1st, 2008

Anathem

I was incredibly excited to read that Neal Stephenson's next novel, Anathem, will be released this September.

does a little dance

The amazon affiliate boxy thing on the right doesn't look nearly as cool as it could with the actual front cover image, but I don't believe one has yet been released, so for now.. empty box. I don't actually care about the 2 cents I'd get if someone clicked on that link and pre-ordered the book. Really, I just wanted a straightforward way to embed some amazon content, and the affiliate account was the fastest way to go.

Hey, it's late.

The back-panel text or, more correctly, "catalog copy" is as follows:

Since childhood, Raz has lived behind the walls of a 3,400-year-old monastery, a sanctuary for scientists, philosophers, and mathematicians—sealed off from the illiterate, irrational, unpredictable "saecular" world that is plagued by recurring cycles of booms and busts, world wars and climate change. Until the day that a higher power, driven by fear, decides that only these cloistered scholars have the abilities to avert an impending catastrophe. And, one by one, Raz and his cohorts are summoned forth without warning into the Unknown.

According to a Q&A published six months or so ago, the book is primarily about Platonic mathematics. I am, therefore, bound to read it in about e working days. Count me pre-ordered!

Hat tip to Nerd World.

Mar 31st, 2008