dannyman.toldme.com

This page features every post I write, and is dedicated to Andrew Ho.

December 15, 2009
Technical

Shell Function: Compare Output of Two Commands

Link: https://dannyman.toldme.com/2009/12/15/shell-function-compare-output-of-two-commands/

I just wrote this up for some test automation. This function gets passed two commands, runs both commands, and returns “PASS” if they match, or “FAIL” with the diff if they do not match.

compare_output()
{
    out1=/tmp/output-$$.1
    out2=/tmp/output-$$.2
    $1 2>&1 > $out1
    $2 2>&1 > $out2
    diff -q >/dev/null $out1 $out2
    if [ $? != 0 ]; then
        echo "FAIL"
        echo
        echo "Details:"
        diff $out1 $out2
        echo
    else
        echo "PASS"
    fi
    rm $out1 $out2
}

echo -n "Test that will fail: "
compare_output 'echo pass' 'echo fail'

echo -n "Text that will pass: "
compare_output 'echo pass' 'echo pass'

Feedback Welcome

December 13, 2009
About Me, Biography, Featured, Sundry

Week of 6 December, 2009

Link: https://dannyman.toldme.com/2009/12/13/week-of-6-december-2009/

Sunday, December 6

I bought a bicycle. There’s a place not far away, Brooklyn Bike and Board, that fixes up old steel-framed bikes because they’re darn tough, then sells them for not a whole lot of money. I spent $250 on the bike, and some more on a front basket and a bike lock. I now have a white, steel, 1-speed bicycle made in France.

I had been avoiding the bicycle thing because Mei is not yet a rider, but on the Greyhound ride back, that college student had mentioned that he’d bought a “recycled” bike for fairly cheap, and rarely spent money on the subway. The prospect of riding around for my own pleasure and exercise pleases Mei. Come Spring we can find her some wheels and learn her how to ride.

Monday, December 7

A day that shall live in infamy or simply “Monday?” For “lunch” I rode up to drop off a bag at Goodwill, and I realized I had totally forgotten my helmet. Fortunately, I made it home safe, then stashed the helmet in the bike’s basket.

When I make coffee I dish the grounds into the filter, and then place the filter into the basket. This reduces the chance of accidentally slopping grounds down between the filter and the basket. Instead I have the occasional accident where I spill coffee grounds everywhere.

Every month or so my Grandmother forwards me another e-mail that has been forwarded to her via a chain of dozens of people who haven’t quite figured out how the Internet works, and these photos are from Miniatur Wunderland, in Hamburg, DE. That’s in the North of Germany, and may likely be on the itinerary of my next trip.

From an e-mail shared with my team at work:

While it is true that I wear dark-framed eyeglasses, post to my highly-customized blog, and Twitter, and uhm, have a 100% telecommute, and just yesterday I bought a “recycled” 1-speed bicycle, I don’t like to think of myself as a hipster, no. And the smart phone and the mini computer . . . gah! This is why I can’t own a Mac or an iPhone or grow a goatee . . .

Tuesday, December 8

Come on ride the snake! Ride it!
Come on ride the snake! Ride it!
Come on ride the snake! It’s a Python!

Wednesday, December 9

New York’s MTA is an excellent system for most parts of New York that existed in the 1920s, when the last major expansions were completed. That means airport service is sub-optimal: ride a local train as far as it will go, then catch a local bus that meanders to the airport.

Note that during peak hours they’ll run that bus line in pairs, but only one bus of each pair runs to the airport. The other goes somewhere else and if you’re lucky the driver will speak up and direct you to the correct bus. If you’re less lucky you can wait fifteen minutes for the next pair of buses.

Note also that if you’re running late and try to use the Virgin America self-service checkin kiosk, it will keep inviting you to try again after you swipe multiple credit cards at different kiosks. If you dig out and enter your confirmation code, it will invite you to try yet again. In this way you’ll not hear the lady announcing that if you want to catch your flight you should come over to the human being right now, because this is the last chance to make it on the flight.

Note also that if you wait behind a family with a newborn and plenty of luggage at security then stroll liesurely to the gate you’ll get to watch the plane you missed push back from the gate and taxi away. And yes, while Google is giving us all free in-flight wireless network access for the holidays, JFK expects you to pay several dollars for the privilege during your hopefully brief wait in the airport.

Thursday, December 10

I helped Todd find an appropriate box into which to pack the extra-large can of Sysco beans.

Friday, December 11

I needed change for Muni so I bought a to-go coffee at the cafe on the corner. I joined a little man at the bus stop as I waited for my cup to cool. He noted my coffee and explained that he was banned from that coffee shop. I offered him a sip, and he worked his way through the entire cup I had only bought for bus change anyway as he repeatedly introduced himself to me as a fan of the Kansas City Chiefs.

Various neighbors passed, exchanging pleasantries with the Chiefs Fan, one saw him drinking from the cup, “that had better be Hot Chocolate.”

“Decaf.”

Apparently I delivered a cup of contraband to a guy who isn’t allowed to drink caffeine.

Saturday, December 12

Mei’s sick. Slept too much, and enjoyed riding my bike down to Roots in the 30 degrees.

1 Comment

December 8, 2009
About Me, Python, Technical

Why Python Can Suck (But I Still Like It)

Link: https://dannyman.toldme.com/2009/12/08/perl-vs-python-documentation/

Based on something I posted to Facebook:

Perl’s “natural language” emphasis and non-obvious locutions encourage developers to document their code. Many times I have put some hard work into a line or a block of code, and ended up writing in some comments as a part of the process.

Python code is nice and readable but often very poorly documented. “The code should speak for itself,” and while it is easier to read Python code sometimes a few human-language comments would save some time and annoyance.

Maintaining Python code is easier than maintaining Perl, but using Perl modules is often easier than using Python modules because Perl developers are kinda forced to explain their work.

One of the first things I had to accept about pydoc is it is almost universally worthless, and even good functional documentation will often omit the sort of useful examples that I am most likely to find quickly intuitive.

This is why I have transitioned so slowly. Python’s strengths breed a certain weakness just as Perl’s weaknesses breed a certain strength.

At this point, I would consider myself approaching bi-linguality, and pretty comfortable in either language. If I have a preference it would be for Python, because I am lazy about documentation and even maintaining my own code, it is a lot easier to figure out what I wrote in Python somewhat after the fact. But my fondness for Perl and its generally more approachable documentation stands, and I’m not about to dis what has served me so long and so well.

1 Comment

December 4, 2009
Python, Technical

Notes on Porting a Django App from SQLite to MySQL

Link: https://dannyman.toldme.com/2009/12/04/django-migrate-database-sqlite-mysql/

This was painful. I’ll be doing this again next week, then hopefully never again.

First off, if you ever hit an error, drop and re-create your MySQL database, or at least drop the tables, or things just get weirder.

Grab the data from SQLite:

python manage.py dumpdata > $APPNAME.json

The, update settings.py to connect to the MySQL database, and if you are really lucky:

python manage.py syncdb
python manage.py reset contenttypes
python manage.py loaddata $APPNAME

(Thank you, Carl Meyer!)

Now, here’s the cute things I ran into. I had originally built a model with a TextField primary key. This is fine by SQLite but when Django tries to create a BLOB field you get in trouble asking for it to be unique, never mind a primary key. Fortunately, it was easy enough for me to simply change it to a CharField, which will tell Django to use VARCHAR. (SQLite certainly didn’t mind.)

The other was that neither Django nor SQLite were enforcing field length limitations, so I would hit some errors when loaddata tried to bring in database entries that were too long. I worked around this by raising my length limitations. There was also some ugliness with a UTF-8 string, which I solved by creating the text object in question.

3 Comments

December 2, 2009
Linux, Sundry, Technical, Technology

Windows 7 vs Ubuntu 9.10

Link: https://dannyman.toldme.com/2009/12/02/windows-7-ubuntu-first-impression/

So, I tried Windows 7 beta, and recently scored a copy of Windows 7 for my desktop PC, via employee discount. (I’d be willing to pay $50 for the OS, so $25 isn’t a bad deal. The again, Microsoft sent me some very large checks for my Tellme equity in 2007 so a very small Capitalist part of me is rooting for them.)

Where do you want to install Windows?

It is pretty nice: basically a refresh of Windows XP, with extra spit-and-polish. Zippier, too! It boots and shuts down faster than XP or Ubuntu, and manages OS updates without requiring my intervention and subsequently breaking things, like Ubuntu does. I was musing to my coworkers that if it had the following, I could switch from Linux:

1) A decent software packaging system.
2) Built-in Virtual Desktops.
3) Middle-button paste.

Boot/Shutdown Speed

I turn my computers off when I’m not using them. I like that Firefox will remember tab sessions. But waiting for an OS to boot is wasted time.

Despite recent improvements, Ubuntu still takes way too long to boot, and seemingly forever to shut down. Windows 7, by contrast, is pretty darn zippy. I like that!

Winner: Windows 7

System Updates

So, for the record, I’m thinking to turn off system updates on my Ubuntu environments, because they aren’t worth it and they keep breaking my stuff. I’ll just refresh twice a year when the new release comes out, therefor managing the pain of upgrades. Windows updates are more important, given the constant security threats. Fortunately, Windows does that for me without my noticing, save the stupid “I will forcibly reboot you in 5 minutes” thing that hasn’t hit me (yet?) on Windows 7.

Winner: Windows 7

Software Packaging

Windows seems to have made some improvements with software packaging, and I gotta say it is convenient to go to a web site, click on an installer, and a few minutes later have the application running. Of course, then there’s another icon on your desktop and the Yahoo! tool bar has been added to your web browser . . .

On Ubuntu, though, most of the time I go to a shell and type:

sudo aptitude install foo

And there I go!

Sometimes software isn’t available in the central repositories, but 9.10 has made adding some PPAs easier. And sometimes I go to a web site, click on a link to a .deb file, it downloads, the system asks for my password, and the software gets installed without leaving crappy toolbars in my environment. Victory!

Winner: Ubuntu

Virtual Desktops

Ubuntu’s Gnome interface would be nicer if I could drag windows to the side of the screen and they’d pop over to the next screen, like the fvwm2 pager. But, I’m pretty well content with Ubuntu’s virtual desktop ability.

You could probably install a decent hack on Windows 7 to get this, but really, virtual desktops and pagers should be built in.

Winner: Ubuntu

Command Line Environment

So, with Ubuntu I can fire off command shells with wild abandon and do what I need to do. (I’m a Unix system administrator, so I relate to computers mostly by typing commands and scripting.) Windows 7 has a new “PowerShell” feature that implements a few Unix commands. After half an hour of searching I discovered that you can get to the PowerShell by hitting Windows+R and then typing “powershell” — heck forbid we should put this in the start menu or make it available by searching for “shell” but okay . . .

With Ubuntu, I can highlight text by dragging and clicking my mouse. This is just like other environments, but instead of hitting control-C (or, ahem Open-Apple-C) to copy the highlighted text into your clipboard, and control-V (I mean, Command-V) to paste from your clipboard, with Unix, whatever you highlight goes straight to the clipboard, and you paste by tapping the middle mouse button.

That can be a little scary sometimes but once you get used to the convenience you really can’t go back to having to mouse and keyboard to cut and paste.

Once you figure out how to launch the PowerShell, you can not simply highlight text with the mouse. Seriously, WTF!? No, this is how you copy-and-paste stuff with PowerShell:

Hit Alt+Space to bring up the console menu, then type ‘E’ to bring up the ‘Edit’ menu and then ‘k’ to start copying or ‘P’ to paste the text in the clipboard to the console. In ‘copying’ mode, you just use the arrow keys while holding down the shift key to select text, and hit Enter to add the selection to the clipboard.

Durr
“Ah, hello, Microsoft? Yes, the 1980s called and they want their primitive user interface back. Thanks!”

Update: You can launch PowerShell is a window that supports text highlighting by dragging the mouse via Start > All Programs > Windows PowerShell > Windows PowerShell. It looks like you can copy highlighted text with control+C and paste with the right mouse button. (Getting closer, I guess!)

Winner: Ubuntu

Focus Follow Mouse

Down in the accessibility menu, there’s an option for “Activate a window by hovering over it with a mouse” . . . but checking that option doesn’t actually change the behavior . . .

. . . correction: it does. After some seconds it brings the window you are hovering over to front. No, I just want focus, not raise! Arrr! Ubuntu knows how to do this, with just a little checkbox.

Update: There are three ways to do this. The registry hack was my solution.

Winner: Ubuntu

Default Web Browser

I’ll give Internet Explorer some credit; I can type whatever crazy thing I want into the URL bar and the second it realizes I didn’t type a URL, it goes over to Bing. Nice!

But then the default behavior is to create new windows all over. Seriously: what is the point of tabbed browsing if you don’t put stuff in the tabs? The big fail though is that for whatever reason the WordPress HTML editor in Explorer keeps jumping up to the top of the text input window, which made working out this post a seriously annoying experience.

A quick install of Google Chrome and my web browsing experience not only interfaces well with WordPress and pops new windows into tabs, but I can type whatever crazy stuff I want into the URL bar and in a not-be-evil sort of way, it shunts me with due humility over to Bing. So, Chrome is my new default web browser for Windows 7. (And I’ll continue trying out Bing, even though I’m a Google fan-boy.)

Winner: Ubuntu

7 Comments

December 2, 2009
Biography, Featured, Sundry

Week of 29 November, 2009

Link: https://dannyman.toldme.com/2009/12/02/week-of-29-november-2009/

Sunday, November 29

After making it home and grabbing a shower, I roamed in search of coffee. Alas, the Tea Lounge was pretty packed, so I wandered down to 5th Ave and ordered a hot chocolate from Ozzie’s. After making sure I was “to stay” they served me in a paper cup with a plastic cap, no whipped cream.

Yeah well, I wandered home and around 4:30pm started watching Nova on the TiVo, but fell asleep hard on the couch.

Monday, November 30

Booked my travel to California for next week. Mei is working night shifts this month but I was able to take her out for sushi this evening.

Tuesday, December 1

Last night I dreamed I was driving an old Beetle in California. Mei was with me and we were going to pick Brian up to take him to dinner. Brian still had long hair but the sides of his head had been buzzed clean.

Wednesday, December 2

Notes from Facebook:

I can only respect a Libertarian if they have the faith in their convictions to homestead in Somalia.

The Constitution enshrines the right to bear arms, in the interests of well-regulated militia. Police forces are a fairly recent innovation, often used in the service of tyranny, like standing armies. Somalia’s system of locally supported militias seems awfully close to a “strict interpretation” Libertarian ideal of limited government, with the burden of personal safety being placed upon the individual.

I walked down to the Tea Lounge for lunch: a giant salad and a pain au chocolat. One man beamed at a friend that the Senate was going to vote today, after setting aside 4 hours for debate. I knew what he was talking about. “You heard about DC,” his friend replied. Later I read a cartoon: why didn’t the Army notice Major Alawi’s erratic behavior? Because he wasn’t acting gay! I laughed out loud.

Thursday, December 3

Today I booked my holiday travel, and this time it is Amtrak all the way. Just over $200 round-trip, but this time my ride to Chicago will be via Washington, DC, where I will switch trains.

On Wednesday I had a small cup of coffee at the Tea Lounge. And a giant salad. That’s the only coffee I have had this week. Trying to “detox” a bit. Quite unintentionally, I haven’t eaten any meat either. A lot of oatmeal. I love oatmeal! Mei is working nights so everything just feels weird. It didn’t help that I managed to watch the six-hour “The Prisoner” mini-series this week as well. I thought it was really very good, and goes well with alcohol, but that means I am out of Scotch.

Tonight I ate a half pound of frozen veggies. Delicious enough but I’m a bit gassy, so it is just as well that Mei is at work.

If I were maintaining a Christmas list, I would add “HP 60 color and black-and-white printer cartridges.”

Friday, December 4

I spent the last of my cash on sandwiches, sodas, flowers, and some whiskey on the theory that Mei might like some tasty sammiches before she had to go to work. Alas, she is off Friday and Saturday night. Doh! We figured we could go see the Mr Fox movie, but ended up relaxing indoors instead. Despite the promised weather report, it did not snow in New York City.

I went to bed with a nasty headache. I rarely get headaches.

Saturday, December 5

I woke up with a scummy throat, and Mei was feeling worse all day. I took her out to Cheryl’s where there was a substantial wait, but it was a deliciously good experience nonetheless. She bought a chicken and stock on the way home and as she set to cooking I went and moved her car, dropping the old printer and scanner at the Goodwill, then scoring a Christmas tree off a friendly French screenwriter outside of the Rite Aid on Flatbush. Back home I sorted through digital photographs while playing “Blazing Saddles” and “Ghostbusters” off Netflix Instant on the TiVo, after which we enjoyed a soup dinner together.

I did not make it to the bicycle recycle store up in DUMBO . . . maybe during the week. I did some Christmas shopping online and built a spreadsheet to track my Christmas gift spending, on the theory that I’ll transfer a certain amount from Savings to cover it all.

What I could also use for Christmas: a wireless Ethernet doohickey for the TiVo HD.

1 Comment

November 29, 2009
Amtrak, Biography, Featured, Movies, Road Trips, Sundry, Travels, USA

Week of 22 November, 2009

Link: https://dannyman.toldme.com/2009/11/29/week-of-22-november-2009/

I don’t narrate my life any more, whether for good or for ill. Well, maybe . . . I should try a weekly update. This has been working well at work, anyway.

Saturday, 21 November

On Friday I took Mei out to dinner, since we were going to not see each other for most of a week. We went to an Indian place up near the Kips Bay theater, where we then saw “Where the Wild Things Are”. I think the first time I saw that book I was impressed with its style, and so my Mom thought I liked the story and read it to me a bunch, but I always thought Max was kind of a spoiled brat. At the end of the movie I mumbled to Mei, “if my son pulls that crap he is not getting any chocolate cake.” When asked if he’d get any dinner, I responded that I wasn’t so sure. I wonder if the kid might have some blood sugar issues such that missing dinner may be a bad move.

Saturday morning, Mei was up early to go to work. I slept in a bit, and treated myself to brunch at Teddy’s, which served me two eggs, fried potatoes, Canadian bacon, rye toast, fruit salad, orange juice and coffee for $8.25. Now, Cheryl’s has some tastier food, so I’ll take Mei over there, but if it is just me, I stick with the cheaper, hearty meal.

I went home, washed the dishes and relaxed a bit, until around 1400 when I rode up to Penn Station to catch the 3:45 to Chicago. Now, a plane would have been faster and cheaper, but now that I live in New York, I can “afford” the relative luxury of a train ride home. The train was pretty full, and a guy named Don sat next to me. I got the modem working on my laptop and caught up somewhat on Internet reading. At Albany they took our engine off the train and shunted a series of cars from Boston onto the front. This was exciting to me, so I shot some dark, blurry video from the passenger area.

I treated myself to dinner in the dining car. Lamb shank, half a bottle of wine, dessert, coffee, and conversation with a cute college couple who were switching to the California Zephyr in Chicago, arriving in Emeryville on Tuesday to enjoy Thanksgiving in Santa Cruz. Robin the Film major and Miru the Art History major. They’re both minoring in Making a Living.

Despite ample legroom and a glass of Scotch from the Cafe car, I tossed and turned a great deal. (more…)

Feedback Welcome

November 18, 2009
Technical

Mutt Macro: Mass-Delete System Spam

Link: https://dannyman.toldme.com/2009/11/18/mutt-tag-prefix-cond/

I just added this to my .muttrc:

macro index Z '<tag-pattern>~f (cron\|nagios\|root)<enter><tag-prefix-cond><delete-message>'

Now if I hit shift-z, all the mail from cron, nagios, and root is marked deleted. If I’m feeling aggressive I can then hit x, which for me means “expunge” deleted messages. (I came from pine.)

Feedback Welcome

November 3, 2009
doodles, Featured

San Francisco Transit Map

Link: https://dannyman.toldme.com/2009/11/03/san-francisco-transit-map/

After several weeks of effort and a few false starts, I present my first transit map, aimed at the casual explorer of San Francisco:

San Francisco Transit Map

You can download the large or 360dpi version from Flickr. Or you can download the InkScape SVG source file from ratchet.

I’m not 100% happy about it, and it is lacking the SamTrans buses I wanted to add. All the same, I’m rather proud. It is train-centric but features connecting bus routes. I managed to include the three levels of rail transit on Market St by consolidating each service into its trunk lines, which let me gloss over the whole KT thing. My original ambition was to populate it with all the landmarks you wouldn’t find on your regular tourist map, but I sort of moved out of town.

Alas, I like to think that modifying info on the map should be pretty easy for others to do. The SVG file contains multiple layers that can be turned on or off, modified, add a new layer . . . you could totally create your own map based on this, if you like . . .

In selecting the size of this map, I went for a square, because despite its free-wheeling ways, San Francisco is geographically quite square, and figured to make the map 15″ x 15″ . . . if one really wanted to one could slice it in fourths and print 7.5″+ on US Letter-sized paper and voila–your own map!

If anyone finds this map useful or hacks on it, please let me know! Enjoy!

Cool link with other maps: http://www.sfcityscape.com/ — see especially the frequent service map in gif or pdf.

1 Comment

November 2, 2009
Dreams, Technology

Dream: Sidekick 4

Link: https://dannyman.toldme.com/2009/11/02/electric-sheep/

I remembered a dream this weekend. I was walking in Bangkok and it occurred to me I should turn off the data on my smart phone, lest I get raped by the service provider. Then I was kind of pleased to see that my smart phone was my Sidekick 2, because that thing was just wonderful.

Then I said to myself “I’m in Bangkok with a smart phone and its a Sidekick 2 when I know I own a G1, so like, am I dreaming?!” And so my unconscious was like shitshit, no look, it says Sidekick 4! Whoo! Shiny! Wouldn’t that make an awesome Android phone!? And I was like “damn, that rocks! When did we come up with this?”

I woke up.

(Thanks for the prompt, RJ.)

Feedback Welcome

November 1, 2009
Sundry

Adventures in Inkscape

Link: https://dannyman.toldme.com/2009/11/01/adventures-in-inkscape/

I have always been enchanted by maps, especially transit maps. I have used the London Tube, New York Subway and Santa Clara VTA maps as wall decor. Earlier this year I began working on my own version of a transit map, “just for fun” to cover transit options within San Francisco. I figured I would focus on making a map that would be useful for casual exploration of San Francisco, showing the metro lines and those bus lines which reliably connect between them.

sftrans-preview2

I shelved the project for a while when it came time to move to New York, but I have finally picked up again, due in part to inspiration from discovering this site, and hope to release an “open source” transit map soon.

sftrans-preview

Speaking of San Francisco, if anyone has a free guest room or couch this Tuesday and Wednesday evening, I would be happy to keep it warm for you! (I have been visiting monthly at my own expense.)

Feedback Welcome

October 29, 2009
Free Style, Sundry

Achewood: North Korean Magical Realism

Link: https://dannyman.toldme.com/2009/10/29/achewood-seriously-wtf/

Todd's Misadventures in North Korean Magical Realism
Glorious Ranger confronts Ultraviolet Thunder over the danger a fish presents to a squirrel’s nuts.

Some people wonder at the recent Achewood story arc, in which Todd, a substance-abusing squirrel, attempts to “piss up a rope” and thereby triggers his transportation into a text adventure game in which he and Kim Jong-il together flee North Korea to found the “PEOPLE’S KINGDOM OF ECSTASY AND WRATH!”

To quote a friend: “Man, Achewood, WHAT THE FUCK . . . I don’t know if [Chris Onstad] is ignorant or nuts.”

So, leveraging my International Baccalaureate high school education, I explained:

He is riffing on a Latin American literary convention known as “magical realism” popularized in the English canon by translations of Gabriel Garcia Marquez.

An example of magical realism can be found in Marquez’ “One Hundred Years of Solitude” when the town of Macondo comes under an insomnia plague. At first, people don’t have to sleep, but then they realize they are losing their memories. So they start putting labels on things to remind them what what they are. And they put a big sign over the main road that says GOD EXISTS. In case one might forget.

In the context of magical realism, it is entirely reasonable that Todd should type with a stutter.

Feedback Welcome

« Newer Stuff . . . Older Stuff »
Site Archive