Friday, November 26, 2010

A Brief Word Of Gratitude

Very seasonal: big thanks to James Golick and John Baku for really making me think; to Paul Dix for making me take my startup ideas more seriously; to Courtenay Gasking for being a very accomodating boss (a year or so ago) and giving me the opportunity to work with (and thereby learn from) amazing programmers like Rick Olson, Kyle Neath, Jeremy McAnally, Trevor Squires, Courtenay himself, and several others; to Frank Wimberly for helping me understand statistical AI; to my customers and coaching clients for all the business over the past year; to everyone who's bought anything through an affiliate link on my site; to all my readers and Twitter followers; to my awesome landlords for hooking me up with such a fantastic apartment; to my acting teachers for teaching me so crazy much, especially Jen Krater and Larry Drake; to Evan Phoenix and Shane Becker for rb.la; to Coby Randquist, Alf Mikula, and many many others for LA Ruby; to everyone who's had me speak at their awesome conferences; to Pete Forde, for special secret favors (ooh la la); to you for reading this; and to so many other people that I can't remember at the moment, my bad for that.

Crucial Vim Tip: Prevents Copy/Paste From Driving You Nuts

Pasting text into a terminal running Vim with automatic indentation enabled can destroy the indentation of the pasted text. This tip shows how to avoid the problem.

Wednesday, November 24, 2010

Tuesday, November 23, 2010

Canopy: Parsing Expression Grammar in JavaScript

Canopy: inspired by TreeTop, runs on JS.Class.

Sunday, November 21, 2010

Where They Put apache2ctl On OS X

/usr/sbin/apachectl

Saturday, November 20, 2010

How To Get In The Zone

Recently, James Golick tweeted the question this post answers. I'm going into detail here because the answer is too long for a tweet, and I'm currently on a self-imposed Twitter ban (I'm not allowing myself back onto Twitter until I've written my own client which enforces my own, very idiosyncratic idea of an ideal Twitter user experience).

The most important thing to understand is that to my knowledge only one researcher has investigated this question in detail and with exclusive focus; that researcher is Mihaly Csikszentmihalyi, and he summarizes his research in the essential book Flow: The Psychology of Optimal Experience.

Csikszentmihalyi's term "flow" expresses the same essential concept as "getting in the zone." A flow state is a state where a person experiences no consciousness of anything except the task at hand. The second and third most important things to understand are 2) that regular experiences of a flow state are the consistent unifying feature of the lives of happy people, and 3) that achieving a flow state requires only two things: that the task at hand be both achievable enough to supply a reward experience of some kind within a relatively short time frame, and that the task at hand be difficult enough that success requires engrossing concentration.

When faced with tasks that are neither achievable nor challenging, flow is impossible; otherwise, all you have to do to achieve flow is segment your tasks into chunks which are both achievable and difficult.

A very important, related data point: procrastination occurs most frequently in the context of vaguely-defined tasks. Thus the same segmenting which sets you up for flow also minimizes procrastination.

It also cures depression, or at least, it did in my case. When I first learned point 2, that flow experiences are the consistent unifying feature of the lives of happy people, I immediately began to train myself on drum essentials like paradiddles. I did this because I was depressed at the time, probably suffering from clinical depression in fact. It cured me of that problem, and I had known from the research that it would. The drum techniques were both achievable and difficult, which made learning them a guarantor of flow, which made me a happy person.

Thursday, November 18, 2010

Higher-Order JavaScript

To my shame, I had to flake on a conference in Sweden called Oredev; to Piers Cawley's credit, he covered for me with what must have been a terrific talk on higher-order JavaScript. Instead of providing his slides online, he instead did a nice, detailed writeup.

Sunday, November 14, 2010

Productivity Boosting Shell Script: Search Gmail Without Viewing Inbox

I'll often go into Gmail to accomplish a specific task and get distracted by shit that doesn't really matter. To solve the problem of entering Gmail to send somebody e-mail, only to be distracted endlessly by new mail, I created a micro-business experiment called Email Without The Inbox. To solve the problem of entering Gmail to search for something, only to be distracted endlessly by new mail, I created a simple bash script for OS X.

Here it is, in its entirety:

# search Gmail THIS WAY, not by going to the Inbox
search_gmail() {
open "http://mail.google.com/mail/#search/$*"
}

Usage:

search_gmail whatever

This takes you directly to your search results from the command line, and allows you to skip entirely the whole distracting experience that is your inbox. Note that it only works for one-word search terms, and would need some minor tweaks (namely URL encoding) to support fuller searches. (I'd put the gist on GitHub and encourage you to fork it, but GitHub appears to be down at the moment.)

Saturday, November 13, 2010

Easily Modify Your Sleep Cycle: Ban Artificial Light After Sunset

JD Moyer blogged about a simple sleep cycle experiment: no artificial light between sunset and sunrise. I read about this a couple weeks ago and immediately put it into action, albeit in an incomplete way (I would do a few hours of limited artificial light after sunset). It made me more energized and rested, and had me waking up much earlier, but I've scaled it back for two reasons. First, it's simply very different from the lifestyle I'm accustomed to; second, I have an acting class every Thursday night, which usually runs to 11pm or later, and a hacker meetup Tuesday nights which goes to 10pm. Both events had me experiencing artificial light until well into the night.

I think this produced a destabilizing effect. Certainly, my diurnal rhythms have varied in some fairly unprecedented ways over the past couple weeks since I first began the experiment. This morning, for example, I woke up at 3:15AM fully rested and energized; last night, I was completely exhausted at 9:30PM and fast asleep soon after. I went back to sleep again this morning, and stayed in bed til around 6:30 or 7, not because I was tired, but simply because without any artificial light, there just wasn't that much else to do. This happened to me at least a few times.

This experiment is a little too much for me as a permanent lifestyle choice, but it's proven incredibly effective, so I'll probably do another, similar short run with it at some later date. I suspect the highly artificial nature of "normal" Western sleep patterns degrades health, so my thinking is I'll use this as a kind of restorative technique to limit that damage.

Friday, November 12, 2010

Simple Web App In Sibilant (Lisp + Node.js)

Sibilant is an awesome project which allows you to write Node.js web apps in Lisp. I used it to create missing-rubyconf.gilesb.com, a simple Twitter scanner which catches tweets about RubyConf. The code is on GitHub.

Hello World In Sibilant (Lisp / Node.js)

my fork of sibilant (contains one tiny patch for Node.js API changes)
Original by Jacob Rothstein
Interactive docs / Web REPL

Saturday, November 6, 2010

Blog Comment Similarity Detector (Free Code For Disqus)

A little while back, a Disqus plugin annoyed me in some way. I don't remember how, but I do remember that I tweeted Disqus about it, and they fixed it, mostly. I've decided to return the favor.

Yesterday, the MetaOptimize blog post NLP Challenge: Find semantically related terms over a large vocabulary (>1M)? attracted a ton of retweets on Twitter. A Disqus plugin on the blog post adds those RTs to the post as "comments," using a system called BackType.

For instance, in this screenshot, the top "comment" comes from a guy called turian, and the bottom comment retweets him.



It would be easy to eliminate the pure, classic, literal RTs with a regular expression:

next if alleged_comment =~ /$RT @/

But if you look in the middle, there's a nearly identical tweet with no actual "RT" string. That's because it comes from @hntweets, which apparently tweets links found on Hacker News, and is apparently not the only such account. Here's another account which Disqus also posted as a "comment" on the MetaOptimize blog post.



There was a third one, too, which I spotted, and probably others that I didn't. I don't know why so many people want to build Twitter bots that retweet links on Hacker News, but I don't see them stopping any time soon, either. Likewise, systems like BackType are systematically vulnerable to spam and noise; for instance, Disqus picked up my tweet complaining about their signal/noise problem as a "trackback."



A spammer could easily tweet a link to the post along with "ch3ap vi4gra here," and, more to the point, a spammer could easily write a script to identify every site that uses Disqus and another script to tweet "ch3ap vi4gra here" along with a link to every blog post on every such site.

There's also two tweets from the same guy, both referring to the same URL (once via bit.ly and once directly):



This means that a spammer could easily fill an entire screen with "che4p vi4gra here," just by submitting the same URL to a variety of URL shorteners.

Any code which combs the firehose needs a noise filter, and the question is how to build it. The regular expression solution won't work here. You can't test for string equality, either. If you take a look at the text of these tweets, you'll notice a ton of very minor variations. Here's one in all lower case:



Here's another screenshot from the same blog post, further down the page, where Disqus posted a ton more tweets as alleged "trackbacks." Again, many feature very minor variations, and none are worth reading.



I've had frustrations with Disqus before, so I should probably just solve this problem for myself with a Zepto bookmarklet which auto-hides the HTML ids typically used by Disqus, but that's not much help to Disqus at all, which means it's no way to return a favor. Plus, it's so easy that it's not worth blogging about. For the record, I've looked at the HTML, and it would probably be as simple as:

$(".disqus_thread").hide();

And the only bit you'd have to think about would be the process of including the Zepto library in a bookmarklet. I've never done that, but it's probably easy.

Because I like a challenge, and I want to create something Disqus can get some use out of, I've written a simple blog comment similarity detector. Since the Disqus code sets up the comments data as JSON, I wrote the similarity detector in Node.js, but I didn't bother to build a server; this is just command-line JavaScript. (Node.js has excellent command-line features.) I used the excellent underscore.js to supplement JavaScript's weaknesses as a language. I used Node v0.2.3, so if you have any trouble running this, just install the old version of Node. (I'm sorry but Node's API changes way too fast for me to give a shit.)

The code knows how to skip highly similar tweets like "foo http://bar" and "RT @baz: foo http://bar", but it doesn't know how to split text strings on hyphens, which would eliminate even more repetition, so if you want to understand this code, get in there and add that trivial feature. The code is simple, brief, and well-commented. It's 146 lines with sample data and comments, 37 lines without. Check it out on GitHub.

Wednesday, November 3, 2010

Monday, November 1, 2010

Having Something In Common With Rush Limbaugh Makes Me Feel Soiled

I'm reading a neat book called The Millionaire Next Door, about how the majority of American millionaires and multi-millionaires live modest lives almost utterly devoid of bling, and I have to say, I'm really glad I bought it on Amazon, because it's a very interesting book, but if I had seen it in a store, I never would have bought it. This is because the cover features an admiring quote from Rush Limbaugh. What kind of idiot wants to read a book about self-discipline and personal responsibility which is endorsed by an obese drug addict? What's next, How To Get Into Harvard, written by Sarah Palin?

Anyway, despite the obvious insanity of whoever is marketing this thing, or perhaps the obvious insanity of the world it's being marketed in, the book is worth a read. And if an obese drug addict can endorse a book about self-discipline and personal responsibility, why can't a painfully recently-failed entrepreneur with no cash endorse a book about multi-millionaires? Seriously, it's well-researched, it documents something counter-intuitive, and it gives insights into how to get rich. All interesting places to start.