Thursday, January 31, 2013

bash versus Powershell

Occasionally, I find myself dumbfounded at how difficult something is in Powershell that is just brain-dead simple in bash.  Then, I remember that the various Unix shell flavors and their POSIX toolset have had many more years to mature than even I have had thus far. The Unix shell tool philosophy is "do one thing and do it well". Doing things well in this context is certainly enabling the most common usage scenarios with minimum ceremony and surprise.

So, let's say you wanted a one-liner that gave the number of lines in a bunch of C# files:
find -name *.cs | xargs wc -l

Now, let's see how to get the equivalent output from Powershell:

gci -filter *.cs -Recurse | 
select @{Name="Lines";Expression={(gc $_.FullName | measure).Count }}, @{Name="Path";Expression={ resolve-path $_.FullName -Relative }} | 
sort Lines | 
ft -HideTableHeaders -Auto

Believe it or not, that is all one line. Of course, wc also gave us a summary row in its output, and we can get that with Powershell, too.
gci -Filter *.cs -Recurse | % {gc $_.FullName | measure }  | measure Count -Sum | select -expand Sum

Now we have a two-liner and tired fingers!

To be fair I am not playing to Powershell's strengths, i.e. .NET accessibility, structured scripting, object pipelining, and a wonderful extensibility story.  With Powershell you won't need the analog of Perl, sed, and awk when the built-in shell functions reveal their limitations.

In fact our Powershell script is a lot more impressive in one respect than its competition; it allowed me to cobble together a "light" version of wc. I was nearly able to duplicate its output. If the roles were reversed, one could almost certainly contrive some Powershell I/O that would make bash look like the verbose, stilted challenger.

So, which shell wins? There's certainly a lot to be said for bash (and most Unix shells); it's power, succinctness, and ubiquity have been honed over more than 30 years. At the end of the day, I'm grateful for the Github for Windows release of a shell that incorporates Powershell and the POSIX tools, so I don't have to choose.

Recommended: The Unreasonable Effectiveness of C

Sunday, August 19, 2012

What Works on the Web

I can't find the quote, but I remember reading around the time of the dotcom bubble a secondhand quote from a Japanese business executive--paraphrasing here--that the only things that make money on the Internet are sex and gambling.  He was wrong; advertising is very profitable.

It's ironic that in the height of the dotcom era, if you had a business plan with a monetization strategy of selling ads, you were often quickly dismissed.  Witness the latter day success of Google and Facebook. I bought a Google beanbag, before they invented Ad Words, because I so desperately needed their product.  Monetization is emergent from network effects.



Back when collegiate Internet stalking (aka The Facebook) was first blowing up, I started thinking about the Internet resources I found indispensable in my brief college career.  In the mid-90s, before Napster/Limewire/Kazaa/torrents, if you wanted free music downloads, you fired up an IRC client, joined #mp3 or #mp3central on Freenode or EFNet, and the friendly bots there would DCC you a list of the mp3 files their owner's had made available.  With patience you could find just about anything you'd want to play at a party.

While I was partying, my roommates were studying and doing homework.  Some of the grad student TAs had setup class websites with Java applet chat rooms.  Other studious individuals would share their answers--and more importantly--how they came to those answers.  These chat rooms were busiest the night before homework was due.

You see, the Internet has always been social.  Anyone wanting to get anything done has always needed other people: tutor, muse, compatriot, nemesis, partner, friend.  At the core of every human interaction is a give and take, a transaction of time or attention prosaically, but in a more important sense, a transaction of an intangible but indelible part of our selves--the currency that makes us human: ego-boo, whuffie, brownie points, karma, influence, power, etc.

If you want to start a company that exists primarily on the web, you'll be engaged in a kind of arbitrage of this human currency.  You must understand your particular arbitrage strategy and be able to articulate it.  This allows you to focus on those features of your service(s) that provide the best leverage and/or growth.

What works on the web?  Making people useful to each other.

Sunday, July 29, 2012

Can Github Save Your Life?


As of late I've had a renewed interest open-source medicine, specifically evidence-based medicine.  My exposure while at Zynx Health and a talk given on OpenEMR is what engendered the interest, and it was recently rekindled by these articles: The Most Important Social Network: GitHub and How we use Pull Requests to build GitHub.

Briefly, the correlation there is that Github is a language-agnostic content management system, with strong versioning and collaboration capabilities.  In evidence-based medicine, treatment and diagnostic decisions are based on rigorous statistical analysis of outcomes. In reality, though, physicians are, like the rest of us, innumerate and busy.  (cf. Do physicians understand cancer screening statistics...). Therefore it is incumbent in practicing evidence-based medicine to distill the research and analysis into clinical pathways that can be employed at the point of care.  Github could be used to author those clinical pathways.

In fact, git as a distributed, decentralized, collaborative, open, secure content management system is ideally suited for this task, when leveraged by the powerful collaboration features offered by Github.  On Github everyday the foremost experts in their field, collaborating from nearly every country on Earth, produce tools that they go on to employ in their work.  The value of this activity then filters down to the rest of the practitioners through third-party systems.

I'm describing software, but I could be describing evidence-based medicine.  

Evidence based medicine is the conscientious, explicit, and judicious use of current best evidence in making decisions about the care of individual patients. The practice of evidence based medicine means integrating individual clinical expertise with the best available external clinical evidence from systematic research. Evidence-based Medicine[...]

In a world where the clinical pathways were created by the foremost experts in their field and made readily available to medical professionals in the field: we make all practitioners more effective; we get lower costs and better outcomes; we can afford to save lives.  

Open-source clinical pathways would provide grist for the mill of healthcare innovation.  Entrepreneurs would create mobile applications that combine location, biometric, and symptom data to suggest diagnostics and treatments with high specificity.  Like the Linux kernel, clinicians could use "builds" from a distributed trust model, where updates to clinical pathways were controlled through the kind of real-world trust and control models that are in place to keep us safe.

What is needed is programming ecosystem for clinical pathways.  I mean that literally.  We need a "byte code" (portability standard), languages, compilers, linkers, theorem provers, IDEs, package managers, etc.  We need all of this to create a bazaar of healthcare innovations, and we need it soon.

Your life may depend on it.



Thursday, June 14, 2012

Learning French in a Hurry: Some iPhone Hacks to Try

My best friend and I—that is, my wife and I—are headed to Paris this Fall.  Unfortunately, no parlez français.  There's this awful rumor (okay, myriad anecdotes) going around that the French are a bit jingoistic, or, perhaps more fairly, intolerant of those who don't bother to learn any French at all before visiting the country, particularly of those Americans who simply expect everyone to speak English in pursuit of the (no-longer-almighty) American Dollar.

Think what you will of this attitude or the veracity of it's justification; it's their country.  When in Paris...

So what is the busy American with about three months to learn French for a trip to Paris to do? First, and above all else, know that only a genius with can learn a language this quickly, so suck it up, be humble when you go, and do your best. Here are some hacks that we are trying out.

Change your iPhone language
You are surely extremely familiar with navigating your iPhone. Plus, the icons make it incredibly easy to find the app your looking for, despite it's caption. Changing the language your iPhone uses exposes you to French words and phrases as often as you check your phone. Since you already know what most of their counterparts are when the phone is using English, you'll surely pick up some new vocabulary and keep it. Immersion is the key to quick language acquisition.
Enable VoiceOver on your iPhone
Reading words is one thing, but it's hardly sufficient. You need to hear and speak them to improve retention and to make practical use of them. This is where the accessibility features of the iPhone come into play. Turn on VoiceOver to have all of the menu items, titles, button, etc. spoken by a clear French accent. Adjust the slider controlling how quickly the words are spoken to a rate your comfortable with interpreting—probably a slow as possible. Finally (and this is important), make sure you set the Triple-click Home feature to toggle VoiceOver. This is the most convenient way to silence the new Frenchman in your phone, but with VoiceOver on it is nearly impossible to do any texting.
Text message to your language buddy exclusively in French
My wife and I are using Google Translate in concert with iMessage for all of our text messaging. Here's the pattern:
  • Type your English in Google Translate
  • Listen to Google's French translation
  • Important! Manually type the translation into iMessage. You could copy/paste if you are in a huge hurry, but this is where you will practice writing and recall of spelling.
  • Copy/paste your interlocutor's response into Google Translate and get the English translation. Yes, do this first; you need to know what the words mean before hearing or writing them.
  • Back in iMessage now, use Triple-click Home to enable VoiceOver. Select the response you just translated to English and listen to it a couple of times, repeating it time. Turn VoiceOver off before repeating these steps.
News in Slow French
This podcast is available for free in iTunes. As a beginner you won't understand much, but it is delivered in a way that is both entertaining and accessible with a didactic slant that sometimes makes it seem a little silly. Remember, immersion is key.
Create a French Radio Station for the Pandora app
We've had decent luck with Carla Bruni (thanks to this Yahoo! answer). The real trick is to cull all of the non-French songs that come up using the thumbs-down button. Give it some time and you should get a pretty good stream of French language music.
Put Google Translate on your Home Screen
This one almost goes without saying, but the Add to Home Screen feature of Safari is under-utilized in my opinion. Quick access to a standalone view of the Google Translate web app will save you a lot of time and frustration in employing these hacks.
Jibbigo

Don't expect miracles here, but when all else fails this app could save you. Jibbigo interprets speech and translates bi-directionally! This means you can speak in English and hear a French translation, and vice versa. The important distinction between this app and Google Translate is that it works offline.

There are two major drawbacks to this app that demand comment. First, it is really, really slow. Painfully. I'm using the iPhone 4, not the faster 4S, but I suspect it will still be awkward to use this in conversation, so don't rely on it. Second, the French speech-to-text function seems unreliable. As I don't speak French, I played Google Translate audio to the phone and got pretty bad results. Not bad for a universal translator, just imperfect enough to frustrate conversation. There is an option to type the words you want translated, so a patient interlocutor can succeed.

Besides an emergency translation, this app is useful in learning French when Google Translate is unavailable for any reason.

Pimsleur on your commute and in the gym
Get the Pimsleur French audio lessons into your iTunes and listen to them on your commute and at the gym. You really need to repeat these lessons, so I suggest doing a new lesson at the gym, or your commute home, whichever is first. Then listen to that same lesson on your morning commute. The sleep between these two periods will help things stick. If you are not sure about your commitment level, buy French, Conversational: Learn to Speak and Understand French with Pimsleur Language Programs (Pimsleur Instant Conversation). Otherwise, get French I, Comprehensive: Learn to Speak and Understand French with Pimsleur Language Programs, since there is a big overlap between the two products.

Those are the hacks we've come up with so far. Do you have a language learning hack for the iPhone?

Tuesday, June 5, 2012

Web Performance: Measure the Right Thing

By attempting to improve your site's page performance, you can actually make it slower. There are numerous well developed techniques to improve the performance of your web sites and applications.  Steve Souders and others have put together some best practices to improve your page performance, and companies like blaze.io have put together turn-key solutions to implement these practices. With these and other ingenious tools that help measure page performance, you'd think implementing a program to improve page performance would be straightforward, but you would be wrong.


Performance improvement is an optimization game, and optimization is the act of maximizing (or minimizing) some measurable quantity.  The conventional wisdom for page performance holds that the time from first byte until window's load event is fired (i.e. time-to-onload, or TTO) by the browser is the best quantity to optimize, as it roughly approximates the wait until the page is interactive. While this seems like the worthwhile goal, it isn't; many of the techniques used to optimize TTO have deleterious effects on the user experience, including making perceived performance much slower.

Consider the practice of deferring the loading of various JavaScript files until TTO.  This generally has a very positive effect on TTO, but can have potentially negative effects. At a former client, a major airline, developers and management became fixated on TTO (as measured internally and by a third party).  The result was that the page would fully render in under a second on average, but some customers would be unable to use the flight search widget properly for twenty seconds or more.

In a somewhat common scenario, the HTML corpus of the page would download, along with the major images assets (hero shot and sprites), and the page would render completely above the fold. The deferred load and execution of the various JavaScript assets would then commence.  Unfortunately, the assets that powered the flight search widget would sometimes take an inordinate amount of time to download, resulting in a much diminished, if not jolting, user experience.

The solution is simple; the prescriptive guidance from Souders and others is to put these assets, those that spark the interactivity of critical features of your pages, inline.  Specifically, including the JavaScript for the flight search widget in a script tag at the bottom of the HTML payload would have made the widget interactive in a timely manner. By optimizing the wrong quantity, the team made things perceptively worse.

What should have been the optimized quantity? The answer to that question could only come from user-experience thinking.  UX is a kind of optimization itself: personas are developed; their goals explored; and the interactions are designed to best help them meet those goals while balancing the personas' agendas against each other. This kind of user-centered exploration of the problem space gives us a tangible quantity to optimize in any given interaction.

In the particular case of an airline's homepage, many agendas begin with searching for a flight; it is clearly the most important interaction. Concordantly, it is the time-to-interactivity of the flight search widget on the homepage that should have been optimized. By prioritizing the interactions on a given screen, we create a ranked list of performance measures that will provide tangible benefits to users of our web sites.

These measures, like time-to-interactivity of the flight search widget, are couched in domain-specific terms. We have to instrument our JavaScript to make them measurable in ways not unlike the DOM onload event.  By segmenting traffic and sending instrumentation data back to a beacon, we can monitor and optimize the real experiences of our customers, instead of a browser event.

Tuesday, April 17, 2012

Using Ruby to Download Files in Parallel

I've been taking a few of the online classes offered by Stanford, and I wanted to write down for posterity (read: me) the way I grab the files I need from the course download page(s).

gem install hpricot
gem install parallel

Wednesday, February 15, 2012

Testing Multiple Versions of IE on any Platform

The best summary of the available options I've found is the article, "Reliable Cross-Browser Testing, Part 1: Internet Explorer". The upshot is that if you want to engage in the article titular activity, you'll be relying on VMs. Having used the other approaches outlined in the article, including Multiple IEs, I have to concur with this conclusion and aver that it is ultimately the only approach that provides the flexibility you'll need when you you need to debug some odd CSS or JavaScript behavior in IE6 with some odd configuration.


So, the real trick is minimizing the pain of getting this setup. If you are running on Linux or Mac OSX, you'll be happy to find out that you're a shell script away (almost). This script uses Oracle's Virtual Box to operate the VPC images. It is ironic that this is the only way that Windows 7 Home/Home Premium users can use these images, since Virtual PC and the XP Mode feature are not available without the Pro or Ultimate SKUs.*

Once you've got the IE App Compat images downloaded, you'll likely find they have a couple little problems: BSOD on boot and Windows activation; you'll find the solution to those problems in this blog article.

* As an aside, how long do you think Microsoft will continue this multiple SKUs? An OSX Lion upgrade is $30--for new VERSION! It doesn't matter, I suppose, given that most folks think Windows 8 will be DOA.