« January 2012 | Main | March 2012 »

February 26, 2012

JavaScript Patterns

JavaScript PatternsJavaScript Patterns by Stoyan Stefanov

My rating: 3 of 5 stars

A grab bag of practices and techniques for JavaScript development for the core language and some browser specific concerns. The Essentials, Literals and Constructors, Functions, Object Creation Patterns, and Code Reuse Patterns chapters mostly rehash material from "JavaScript: The Good Parts". The author provides additional exposition on the concepts but doesn't introduce much new material. The Design Patterns chapter includes some good examples of JavaScript implementations but accurately points out many already exist in third party libraries. The DOM and Browser Patterns chapter provides a brief introduction to browser specific concepts and concerns but you'll want to consult the referenced books for more detailed discussions. This book is a great primer for JavaScript development due to the breadth of topics is covers but is worth a pass if you've already read other JavaScript books covering these topics.

View all my reviews

Tags: books javascript

February 14, 2012

Willpower: Rediscovering the Greatest Human Strength

Willpower: Rediscovering the Greatest Human StrengthWillpower: Rediscovering the Greatest Human Strength by Roy F. Baumeister

My rating: 5 of 5 stars

A wonderful exploration of willpower. The book reads easily and includes many references to research performed by the authors and many other scientists. It opens with the history of the discovery of willpower and that willpower is a limited but renewable resource. Next it dives into how humans can survive this depletion of willpower and most importantly setup conditions to remove the need to use willpower in the first place. Most encouraging the book concludes with a review of why willpower matters and the various techniques to strengthen it.

View all my reviews

My notes are below.

  • Willpower in children is biggest indicator of future success. [10]
  • 1. You have a finite amount of willpower that becomes depleted as you use it. 2. You use the same stock of willpower of all manner of tasks. [35]
  • No glucose, no willpower. [49]
  • Zeigarnik effect: The unconscious is asking the conscious mind to make a plan. [83]
  • Keeping options open leads to long-term problems. [102]
  • For contentment it pays to look at how far you've come. For motivation and ambition focus on the road ahead. [120]
  • Any willpower exercise strengthens overall willpower. [137]
  • Precommitment: lock yourself into a virtuous path. [151]
  • Successful precommitment can turn into something permanent: a habit. [154]
  • Self-control turned out to be most effective when people used it to establish good habits and break bad ones. [157]
  • "Why" questions push the mind up to higher levels of thinking and a focus on the future. "How" questions bring the mind down to low levels of thinking and a focus on the present. [164]
  • A personal goal can seem more real once you speak it out loud, particularly if you know the audience will be monitoring you. [177]
  • Hyperbolic discounting: We can ignore temptations when they're not immediately available, but once they're right in front of us we lose perspective and forget our distant goals. [184]
  • Bright lines: clear, simple, unambiguous rules. [185]
  • High self-esteem increases initiative and it feels good. [192]
  • Set clear goals, enforce rules, punish failure, and reward excellence. [197]
  • Three basic facets of punishment: severity, speed, and consistency. [199]
  • What-the-hell effect, once a goal is blown people over do it. [221]
  • The willpower depleted state makes you feel everything more intensely than usual. [227]
  • Better to say Later rather than Never. [237]
  • Set three goals each week, can't work on anything else until those are done. Review each each. [251]
  • When you set a goal, set a reward for reaching it-and then don't stiff yourself. [257]

Tags: books

February 12, 2012

2011 Spam

In 2011 I saw a dramatic reduction in my daily spam e-mail volume, just 21,744 messages, down from 63,436 in 2010. Seems as though the takedown of the Rustock botnet was the major reason for the reduction as seen in the graph below. 60 spam messages a day is manageable, especially when I only deal with them once a day when I get the report from Postini. A few false positives and false negatives but compared to years past of 240 spam messages a day I'm much happier.

Tags: spam

February 9, 2012

An object unlike others: process.env

Yesterday I found myself playing with a configuration hierarchy. Anything set in the environment would override anything defined by a defaults.json file which would override anything hardcoded into the application. My initial attempt led me to discover some interesting things about node's process.env object. Without further ado:


Any guesses what the output will be?

With node 0.6.10 I get:

TypeError: Property 'hasOwnProperty' of object #<error> is not a function

Not what I was expecting. What about a different test:

console.log('hasOwnProperty' in process.env);
// output -> true
// output -> undefined

Fun. I've not look at the node source but given that the environment could define a property called hasOwnProperty it makes sense that process.env masks the standard prototype model even if the in operator exposes it.

Besides being a fun exercise playing with node, why does this matter you might ask? What started this all was detecting if an environment variable existed but was set to the empty string. The standard if check fails:

// This simulates launching node like: EMPTY= node env.js
process.env.EMPTY = '';
if (process.env['EMPTY']) {
} else {
    console.log('DOES NOT EXIST');
// output -> DOES NOT EXIST

Since the empty string is falsy in JavaScript this doesn't work. As we saw above doing a hasOwnProperty check won't work and the in operator could give false positives.

Thinking outside the box, given that the source of the values in process.env is the environment node was launched from, we know that the environment can't set a property value to be undefined. The simple existence check then is to see if the value is undefined:

console.log(typeof process.env['EMPTY'] !== 'undefined');

Or just use underscore's isUndefined method since you should be using that library anyway.

Just because we can't call hasOwnProperty() directly on process.env doesn't mean we can't still use it. Instead we just need to call it indirectly:

console.log(Object.prototype.hasOwnProperty.call(process.env, 'EMPTY'));
// output -> false
process.env.EMPTY = undefined;
console.log(Object.prototype.hasOwnProperty.call(process.env, 'EMPTY'));
// output -> true
process.env.EMPTY = '';
console.log(Object.prototype.hasOwnProperty.call(process.env, 'EMPTY'));
// output -> true

Tags: javascript nodejs

February 6, 2012

You Are Not So Smart

You Are Not So Smart: Why You Have Too Many Friends on Facebook, Why Your Memory Is Mostly Fiction, and 46 Other Ways You're Deluding YourselfYou Are Not So Smart: Why You Have Too Many Friends on Facebook, Why Your Memory Is Mostly Fiction, and 46 Other Ways You're Deluding Yourself by David McRaney

My rating: 5 of 5 stars

A lovely expansion and refinement of content from youarenotsosmart.com. Each chapter covers with examples and referenced research a psychological misconceptions most of us are unaware we have or make. Very readable and eye opening. To remember even half of what the book contains would give you a fresh set of eyes to perceive the world with.

View all my reviews

Tags: books life

February 3, 2012

The Information: A History, a Theory, a Flood

The Information: A History, a Theory, a FloodThe Information: A History, a Theory, a Flood by James Gleick

My rating: 4 of 5 stars

Information as we call it today has a rich history and this book explores all that goes into our present day understanding of it. The central character is a man named Claude Shannon who wrote the seminal paper on information theory but touches on many other key individuals like Charles Babbage, Samuel Morse, and Alan Turing. The book reads easily despite the wide range of topics and concludes with astute observations about the role of information in today's world.

View all my reviews

Tags: books


ReamdeReamde by Neal Stephenson

My rating: 4 of 5 stars

An enjoyable world encompassing romp building heavily on computer geekery circa 2010. At times bogged down in extraneous exposition it otherwise follows a fanciful but plausible storyline, casts intriguing characters, and concludes with one of his better written endings.

View all my reviews

Tags: books