Tuesday, September 30, 2014

Book Review: The Checklist Manifesto

I recently picked up The Checklist Manifesto by Atul Gawande, recommended to me by rave reviews on Amazon. However, once I picked up the book, I felt like it left much to be desired.

I was really pleased, initially, that it was a mere 200 pages. I reckoned I could knock it out in a week, and I was right. The unfortunate part was that it felt like I really long article that had been fluffed up into a book. They key point the author is trying to drive home is that checklists are useful because humans are fallible and they make elementary mistakes. He does this through the use of many many anecdotes, spread across three industries - medicine, construction, and aviation.

The writing style of the The Checklist Manifesto is in the classic pop psychology fashion - riveting anecdotes told over the course of a chapter or so, punctuated by studies and statistics, often also told in an anecdotal manner. This isn't necessarily bad - the Gawande just doesn't have enough content to support it. Other, similar books have better structure. The Power of Habit is divided into three parts - the habits of individuals, those of organizations, and those of societies. Switch by Chip and Dan Heath has its three steps of change. The Checklist Manifesto is just barely meaningful meandering.

What The Checklist Manifesto does get right, however, is its core point. Atul Gawande is a surgeon, and as a software engineer it's hard for me to relate making websites to the life-or-death situations that surgery brings, it's easy to translate what he's advocating to developer terms - that in the end, human beings have limited cognitive capacity, and that the best way to unleash higher potential is to automate away the grunt work, so that more cognitive capacity can be spared for the really important stuff. Checklists are a means of such automation.

He also advocates checklists as a communication tool - the checklist becomes a tool of who needs to communicate what at different stages of the operation. This makes sure that everybody is on the same page regarding the operation, and allows anybody to bring up any concerns, and makes sure everybody knows all the relevant information before beginning the operation. He cites an example of one operation where something critical the anaesthesiologist should have known was only communicated to him because the checklist caught it. In this case, the patient might have died, had that critical piece of information not been communicated to the anaesthesiologist.

So long story short - the book is a nice, short read at 200 pages, but it could've been shorter still. Check it out The Checklist Manifesto on Amazon if you'd like to read it (disclaimer- that's an affiliate link).

Thursday, September 25, 2014

Lessons From Building My First Website

I made my first website at http://searchgovernmentjobs.org/ a few days ago - it's at a thin wrapper around a government API that I found at http;//digitalgov.gov. It allows you to search the government API for jobs using queries, examples of which I've included on the search page. The results are all from http://usajobs.gov.

My original intention was to just get something out there on the internet. In doing so, I learned some valuable lessons:
  • I learned about DigitalOcean (disclaimer: referral link), based on a question I had asked on HackerNews
  • I learned at least the basics of navigating the default Django stack that comes on a DigitalOcean Django droplet. See my post here for one such lesson that I learned. 
  • I learned how to buy a domain name at 1and1.com. (disclaimer: referral link)
    • Fun Fact: I had originally intended to name the site: searchgovernmentjobs.us - but it turns out that using the .us TLD forbids you from using the privacy coverage provided your hostname provider. It has to do with the rules of the organization that administers the .us TLD. 
  • I learned how to configure the 1and1 DNS record to point to the nameservers at DigitalOcean
  • I learned that there are Adsense alternatives. I'm using Chitika for the moment. (disclaimer: referral link)
Now that I have the site up, I'm going to look and see if I can do some SEO to get it up the ranks in search engine pages. Ideally, I would like the site to be self-sustaining in that it should pay for hosting and domain fees out of its own ad revenue, but I don't anticipate being very successful in this regard. The Jobs spaces is pretty filled up with SEO optimized sites and the keywords are very crowded. Nonetheless, I shall try, and in doing so, I may learn something about SEO.

Tuesday, September 23, 2014

The Power of Habit - So You Like Your Oreo Fix

This is another idea I got from The Power of Habit by Charles Duhigg: a great way of quitting bad habits is to not get into them in the first place. Here's an example:

Recently, I've been stopping by a 7-11 on my way home from work and picking up a snack - such as oreos. This happens fairly regularly - at around 6:30 on weekdays, I'll pick up my oreos and then go on my way home.

After about two weeks of doing this, I noticed that at around 6:30 every weekday, I develop a terrible craving for oreos, and feel a tremendous urge to go into that 7-11 and pick them up. Skipping my 7-11 visit has started to require incredible amounts of willpower.

So what happened? Using Duhigg's Habit Loop model, I realized that I had classically conditioned myself to expect oreos at 6:30 on weekdays. This means that my body had been trained to expect them, and so the anticipation manifested as the craving that was so difficult to resist.

Using the Habit Loop model, my cue is the time of day and the sight of 7-11. The behaviour is buying and eating oreos, and the reward is the sugar rush I get from it. After an extended period reinforcing this loop for my brain, seeing the cue was enough for my brain to start anticipating the reward, resulting in a manufactured craving that wouldn't go away until I partook in the behaviour that resulted in the reward.

Now how to fix this - giving up my oreos completely is not something I'm willing to do. I love oreos and am unashamed of my indulgence. The problem is that I want to eat oreos when I actually feel like eating them, and not because my body is manufacturing a craving just because it happens to be expecting them.

The solution, as I've gleaned from Duhigg, is to keep my oreo supply unpredictable. By preventing the association between any single cue and my oreos, I can keep my brain from automating away the behaviour by forming a habit. This way, every time I buy oreos, it will be conscious decision that I will likely have thought through, and not automatic behaviour.

It's difficult to do this when you have a regular job with regular hours, but I could get around this, for example, by varying up the source of my oreos. I could get them from 7-11 one day, and then get them from Jewel or Target the next time. I could also vary up the time - maybe I could get them with lunch one time, and the on the way home the next time. Finally, I could also vary up the frequency - I could eat oreos for two successive days, and then skip three days, and then eat the following day.

So remember: our brains are automation machines. Don't let them automate bad habits. Bad habits are easy to build and hard to get rid of. You don't need to completely stop a behaviour in order to prevent the bad habit from forming - you can do it by varying up the cue and hence prevent the cue-reward association from forming. After all, life is short, and we all deserve the occasional oreo fix. :)

Here's the affiliate link to the The Power of Habit if you'd like to support my blog. And here's the non-affiliate link if you're not into that. :)
The Power of Habit by Charles Duhigg

Monday, September 22, 2014

Working Better

For as long as I can remember, I've had Gmail, Google Voice and Google Calendar tabs perpetually open in my browser. However, after reading this article on Working Better by Paul Jarvis, I've decided to close the Gmail and Google Voice tabs in order to "Turn off every notification."

This is a difficult decision to make because a lot of my friends and some close family are long-distance at the moment, and removing these tabs is going to make me significantly less responsive to their texts and emails.

I'm also experimenting with making my browser full-screen when working on the internet, in order to allow for better focus. The result is interesting because the browser tends to look more like an app when doing this - one of the things I loathe the most about the app-based mobile ecosystem is the inability to run apps side-by-side - but I do think that it has been helping me.

The other suggestion that I really like is, "Keep a log of what you eat during the day and how you feel afterwards." I don't think I'll be able to implement this one just yet, but it's something I definitely want to plan towards in the long run. As I've aged, I'm discovering more and more the impact that small, everyday things like the food I eat has on my health and comfort.

I'm not sure how to approach this subject because of the sheer amount of misinformation available in the food and nutrition space. One thing I've been thinking of doing is to start having a "salad lunch" day once a week to get some fibre going through my system.

If you have time, give the article a read. It's a quick and simple read, and well worth the time.

Sunday, September 21, 2014

Discovering AngularJS

I've recently been pointed towards AngularJS by a mentor. At work, we typically use BackboneJS for our client-side framework needs. Since Backbone is so minimalist, over the past few years we've learned some (sometimes expensive) lessons and developed a set of best practices that minimize the pain of developing with Backbone.

The first thing I noticed when looking at Angular was how many of those implicit lessons and best practices become unnecessary! For example, it's not unusual for me to have to reimplement two-way binding for every application, and I've seen some complex mechanisms to do as-you-type filtering of a list. With Angular, it's so incredibly easy!

For example:

    <body>
        <div class="container" data-ng-controller="SomeController">
           
            <h3>Controllers</h3>
            Name: <input type="text" data-ng-model="nameFilter" />
            <ul>
                <li data-ng-repeat="person in people | filter:nameFilter">
                    {{person.name | uppercase}} loves {{person.city | uppercase}}
                </li>

            </ul>
        </div>
       
        <script type="text/javascript" src="js/libs/angular.min.js"></script>
        <script type="text/javascript" src="js/viewcontrollerscope.js"></script>
    </body>


And in the JS:

var demoApp = angular.module("demoApp", []);

var controllers = {};

controllers.SomeController =  function ($scope) {
    $scope.people = [
        { name: "Kim", city: "Green Bay" },
        { name: "Ron", city: "Miami" },
        { name: "Rufus", city: "Houston" },
        { name: "Wade", city: "San Francisco" }
    ];
};

demoApp.controller(controllers);



Boom! That's it. Most of that code is just boilerplate required to setup Angular itself, and one you do that, the filtering mechanism is handled within the bolded part of HTML template. Isn't that incredible?

I think I'm a little biased against Backbone because it was my first JS framework, and so the learning curve was obviously higher. However, I have to acknowledge, that Backbone is incredibly useful for adding small, clientside-driven pieces to an application. As far as I can tell, Angular seems much better oriented towards writing applications that are entirely clientside, single-page applications.

I highly recommend this tutorial for learning Angular. I found it incredibly useful. Let me know if you have any recommendations for Angular-related resources!


Wednesday, September 17, 2014

The Power of Habit - Willpower

I'm about halfway through The Power of Habit by Charles Duhigg now, and ever since his note on Keystone Habits, the book has been dragging on for a bit. I'm going to ignore his ramblings on organizational change and focus on the part that stood out to me the most in my reading today: his commentary on willpower and its role in habit formation.

I learned somewhere in High School the analogy that willpower is a finite resource. The more you use it, the more it gets depleted. Somehow, I feel like I internalized this in such a way that because willpower is a scarce resource, it should be conserved to be used when important. For example, I considered it okay to binge on snacks and junk food during exam-time when I had to use my willpower to focus on studying.

The Power of Habit likens willpower to be more like a muscle. The more you use it, he claims, the stronger it gets. This analogy is interesting because if it's more accurate than my idea of a finite resource, then my attitude towards willpower is like that of a man who is afraid that he might need to run someday, so he conserves his ability to run by never running. Of course, muscles being what they are, such a man would soon not be able to run very far at all.

The Power of Habit's suggestion (I had to weave through a good one-sixth of the book before I was able to distill it out) is that we can improve willpower by pre-planning our habits. So for instance, if you would like to get into the habit of ironing your clothes for the next day when you get home from work today, you should visualize in the morning how you're going to feel when you get home, how tired you'll be, and how you'll overcome that tiredness to power through and iron your clothes.

Another way of looking at it is that you would be "priming" yourself into making falling into the routine of ironing your clothes easier.

Here's what you can do: think of a habit you want to develop. It might be ironing your clothes at a certain time, or writing a blog post before bed, or cooking dinner instead of eating out. Visualize the crux moment when you usually give into temptation and ignore the task/chore you need to do and imagine yourself overcoming it. Do this everyday in the morning and hold on to it until you are able to develop the habit.

Here's the affiliate link to The Power of Habit if you'd like to support my blog. And here's the non-affiliate link if you're not into that. :)
The Power of Habit by Charles Duhigg

Tuesday, September 16, 2014

The Power of Habit - Keystone Habits

Continuing my reading today of The Power of Habit by Charles Duhigg, I came across The Power of Habit's concept of "Keystone Habits." He presents this, in particular, in the context of organizational change - changing one key habit can spiral into other changes that blossom into large-scale shifts in the organization in question, but suggests that it can be applied on the individual level as well.

The man The Power of Habit uses to present this idea is Paul O'Niell. O'Niell was the CEO of the aluminium manufacturing company Alcoa, and when he came in, Alcoa wasn't doing very well. There was a great deal of friction between management and unions, competitors were stealing business, and morale was low amongst employees.

O'Niell, The Power of Habit says, understood the power of keystone habits (it's funny how often these self-help books explain successful person X as understanding attribute Y of the framework they're presenting). He decided to focus on the keystone habit of "safety" and focusing on this habit improved operations all over Alcoa, and helped make the company ridiculously successful over O'Niell's tenure.

This in itself made me pause for a bit. While O'Niell's success in undeniable, is safety something you can call a habit? I would call it more of a priority, or a value, as opposed to a habit. Additionally, The Power of Habit fails to recognize what focusing on safety truly was for O'Niell - it was a political master-stroke. Faced with an environment fraught with labour-management tensions, safety was the banner everyone would have to rally behind, or else they would be painted as black sheep. What union leader, or manager would dare oppose an action justified in the name of safety?

The icing on the cake for this portion of the book though, was a passage in which The Power of Habit describes how, during his tenure on some government job, The Power of Habit was trying to solve the problem of child mortality, and he traces the root cause of the problem from child mortality to child malnutrition to the child's mother's malnutrition during pregnancy to the mother's education to the mother's teachers to those teachers' college education in nutrition and biology. This is where, The Power of Habit says, O'Niell attacked the problem. And then right at the end of the passage, he tacks on, “Today, the U.S. infant mortality rate is 68 percent lower than when O’Neill started the job.”

Like, really? You're going to tell me (or at least heavily imply) that just because O'Niell recommended changing a few curricula, the US has less infant mortality today? There's absolutely no support of this claim, and it's a basic correlation-causation error any Psych 101 student can spot. The Power of Habit lost a lot of credibility in my eyes with that claim, and this Daily Beast article suggests O'Niell himself disavowed himself from that statement.

That said, I do find the idea of keystone habits on an individual level interesting. It related with a concept I read in Switch: How to Change Things When Change Is Hard about how, when attempting to change, we should take a single, actionable item, and focus on that. Once that change is achieved, it provides the momentum to create a ripple effect that causes other, hopefully positive changes.


To this effect, I'm personally trying to cultivate in myself the habit of writing more often. I'm hoping that developing this will be a keystone habit will have a spillover effect by improving my communication skills, comprehension and whatnot. I don't think it will reduce the infant mortality rate of the US by two-thirds, but then again, not all of us can be Paul O'Niell.

Here's the an affiliate link to The Power of Habit if you'd like to support my blog. And here's the non-affiliate link if you're not into that. :)
The Power of Habit by Charles Duhigg

Monday, September 15, 2014

The Power of Habit - the Habit Loop

The Power of Habit by Charles Duhigg is a book I picked up recently from my local library. At about 25% in, it's already had a decent impact on my worldview, and I think it promises to be a good read. For this blog post, I want to write about the model The Power of Habit presents of habits.

The Power of Habit by Charles Duhigg 

First of all, habits are relatively simple things. It's when hundreds, even thousands of these coalesce around a single individual do they emerge as something as complex as the "lifestyle" of that individual.

Habits come from a three-step loop, says The Power of Habit. The first step of the loop is the "cue". This is what triggers the automatic behaviour, letting you relinquish your cognitive control. Since our brain is evolutionarily programmed to exert as little effort as possible, it is constantly on the outlook to set such "cues" that allow it to revert to default behaviour, and hence save you from expending too much brainpower.

The next step in the loop is the actual action that gets triggered.

The final step is the reward - this, says The Power of Habit, is what tells the brain whether the action it just took should be repeatable or not. The higher the reward, the more likely your brain is to want to engage in that behaviour again.

The Power of Habit uses the example of brushing teeth in his book. Back in World War One, he says, bad dental hygiene was on the verge of becoming a national crisis. In those days, hardly anyone brushed their teeth. Toothpastes and brushes for hygiene were regarded as the proverbial snake-oil. However, after an ingenious marketing campaign by a man called Claude Hopkins, by the time World War Two rolled around, it was discovered that nearly half the men in the Army were brushing their teeth regularly!

Hopkins worked his magic by associating a behaviour with a cue, and a reward the with behaviour. In this case, he used the filmy coating that we can feel on our teeth as a "cue". The behaviour he encouraged people to do was brush their teeth using the toothpaste he was marketing (a brand called Pepsodent), and the reward they got for it was a minty freshness from the toothpaste.

The Power of Habit notes that the minty freshness that we now associate with a clean mouth was a relatively new phenomenon back then, and that it has no effect on actual oral hygiene. In fact, many leading dentists of the day disclaimed Pepsodent as a farce, because it so heavily advertised the feeling of freshness. However, Pepsodent succeeded where so many other toothpaste brands failed because it gave its buyers a tangible reward (minty freshness) as opposed to a promise of good oral hygiene.

So there you have it - that's the Habit loop. Cue, behaviour, reward. This sequence evolved into a habit when it's repeated enough times so that through classical conditioning the brain starts anticipating the reward as soon as it sees the cue. This elicits an automatic craving that can't be satisfied until the behaviour is performed.

Here's the an affiliate link The Power of Habit if you'd like to support my blog. And here's the non-affiliate link if you're not into that. :)
The Power of Habit by Charles Duhigg

Sunday, September 14, 2014

Modifying the DigitalOcean django one-click project to use a custom directory

Hi all,

I recently gave DigitalOcean a shot on the recommendation of someone at HackerNews. DigitalOcean has a lot of custom droplets, which are basically Virtual Machines, that you can use to set up a cloud server on which to host your website.

I had been building a Django website that I wanted to put up, and while setting it up on DigitalOcean, I ran into the following problem: The default Django droplet uses a base Django project located in the 'home' directory of the UNIX installation DigitalOcean sets up for you. I wanted it to point to a custom directory in the /opt folder that I had set up.

In order to do this, remote into the DigitalOcean droplet. Once there, run the following command:

    sudo nano /etc/init/gunicorn.conf

In this file, change 'chdir /home/django' to point to the directory that contains your django project. In my case, I changed it to '/opt/venv'.

Change the 'name' field to refer to the folder that contains your 'wsgi' file. In my case, I changed it to 'name=jobs'.

Change the 'pythonpath' field to refer to folder that contains your 'manage.py' file. In my case, I changed it to 'pythonpath=search-jobs'.

In 'django_project.wsgi:application' change 'django_project' to the name of your Django app (ie. what you changed your 'name' field to).

Now run the following command:

    sudo nano /etc/nginx/sites-enabled/django

In this file, change the media and static locations to point to where you need them to point to. In my case I changed:

    alias /home/django/django_project/django_project/media;

to:

    alias /opt/venv/search-jobs/media;

and:

    alias /home/django/django_project/django_project/static;

to:

    alias /opt/venv/search-federal-jobs/staticfiles;


That should set up the default nginx and gunicorn to serve your django project located in your custom path properly!

If you have any feedback on this post, or if it helped, drop me a comment and let me know.