TJ Holowaychuk

month

April 2010

8 posts

How I Made $2000 Writing An eBook

Roughly one month ago I wrote Advanced JavaScript, a $4, 60 page eBook written using XML and DocBook.

The main reason I went with DocBook was because I could control syntax highlighting for code snippits, however there are other benefits as well such as outputting several formats like ePub, PDF, etc. I would recommend against this unless you have large snippits of code, because it can take some time to get started, but if you go that route I would recommend taking a look at Brian Hogan’s docbook build chain.

The eBook it self probably took around 3-4 hours to write, so over all it was worth the time, and worth helping out the community by sharing some knowledge. Instead of setting up a dynamic site with payment support and all that jazz, I went the simple route and used e-junkie for only $5 per month it was worth the saved time.

I choose to go with a $4 price point simply because I wanted the eBook to be widely available, and for less than a Starbucks coffee why not buy it! This approach differed greatly from the majority of eBooks I have seen, however I had a feeling that I would sell many more, and in turn get the word out much more. Although you could write an enormous eBook and sell it for $20-30 I would highly recommend making it short but sweet.

I hope this encourages you to explore sharing your knowledge, and perhaps learning things you have wanted to learn all along, and then share your results as an eBook!

Apr 16, 20106 notes
Node Version Manager Preview

The Node Version Manager or nvm is a bash script for installing, and switching releases of NodeJS so that you can test your libraries (or deploy) using any release you need.

Tim (creationix) just started this library earlier today, so I forked away and started adding features and refactoring existing code. Currently to use my changes you have to clone my refactor branch:

  $ git clone git@github.com:visionmedia/nvm.git
  $ git pull origin refactor && git checkout refactor
  $ sudo make install

And add the following line to your profile to provide the nvm specific bin directory to $PATH.

  export PATH="$PATH:$HOME/.nvm/current/bin/"

It is super early in the game but already it is a handy little tool.

Installing A Release

The command below will install a release of node run:

  $ nvm install v0.1.91
Installing From HEAD

Installing node’s HEAD or “edge” is as simple as:

  $ nvm install head

which will clone the git repo and build from source. Sequential invocations of this same command will then pull, updating the repo and building from source again. This is a good way to keep with the times :)

Listing Installed Versions

The command list command (also aliased as ls) will list the installed versions, and prefix the active version with the * character.

    $ nvm list
        * head
        v0.1.91
Switching Versions

To switch or “use” a version simply run:

  $ nvm use v0.1.91

After which you should see:

  $ node --version
  0.1.91

If you have not previously installed the given version, then nvm will attempt to install it.

Remove Versions

You can remove “head” or any other version just like you installed it:

  $ nvm remove v0.1.90

This command is aliased as rm, and remove.

List Available Versions

To list the latest 10 releases of node run:

  $ nvm versions

which will output something like below, giving you a better idea of what you can install.

v0.1.91
v0.1.90
v0.1.9
v0.1.8
v0.1.7
v0.1.6
v0.1.5
v0.1.4
v0.1.33
v0.1.32
WOW COOL WHAT ELSE?

Another library you might be interested in, is the Kiwi package manager for node. Although it is in it’s early stages as well, it has served over 1700 packages (aka “seeds”), hosts 40 unique seeds, and over 107 versions of those.

Apr 15, 201010 notes
#nodejs #nvm
Express 0.9.0 released

A few minutes ago Express was released, packed with tons of bug fixes and features.

Installation

As always Express can be installed via the Kiwi package manager for NodeJS using one simple command:

$ kiwi install express

Alternatively you can Download a tarball, or install via Git:

 $ git clone git://github.com/visionmedia/express.git
 $ cd express && git submodule update --init
New Haml Support

I wrote another JavaScript implementation of Haml simply because haml-js was a little clunky and did not comply with the original Haml implementation. My implementation is about 4 times faster (not that it really matters once caching is involved), and more compliant.

“max upload size” setting

We added a simple “max upload size” setting which checks multipart post body Content-Length and raises an error when the specified size is exceeded.

set('max upload size', (5).megabytes)
Request#render() callbacks

The Request#render() method now accepts a trailing callback function, which passes an exception (if a problem occurs), and the final view rendered.

self.render('user.html.haml', function(err, contents){
  // perform caching etc
})
Map Route Parameters With param()

The param() DSL-level function allows mapping of parameter names to preprocessor functions. In the example shown below we want to prevent users from typing an invalid path such as /user/rawr, as we need a user id. Our function passed to param() accepts the path segment, which when returning false will be disregarded as a valid route, and the router will continue searching for a matching route. Otherwise if parseInt() succeeds the id variable passed to our route is now a Number and not a String.

param('id', function(val){
  val = parseInt(val)
  return isNaN(val) ? false : val
})

get('/user/:id', function(id){
  return 'User ' + id
})

In the near future I plan on having parameter preprocessing async-friendly, so that for example :user_id could be used to load an User record from the database.

Unified Exception Handling With error()

The error() DSL-level function is passed the exception thrown. Keep in mind that with async environments like node we loose context if an exception bubbles, so we pass them to Request#error() to allow for the unified error handler shown below.

error(function(err){
  this.contentType('html')
  this.halt(200, '<p><strong>Error:</strong> ' + err.message + '</p>')
})
Handling Missing Pages With notFound()

The request level method Request#notFound() is now used in place where you would normally call halt(404), and supports deferring to the DSL-level function notFound() as shown below:

notFound(function(){
  this.halt(404, 'your lame')
})
Changelog
  • Added DSL level error() route support
  • Added DSL level notFound() route support
  • Added Request#error()
  • Added Request#notFound()
  • Added Request#render() callback function. Closes #258
  • Added “max upload size” setting
  • Added “magic” variables to collection partials (__index__, __length__, __isFirst__, __isLast__). Closes #254
  • Added haml.js submodule; removed haml-js
  • Added callback function support to Request#halt() as 3rd/4th arg
  • Added preprocessing of route param wildcards using param(). Closes #251
  • Added view partial support (with collections etc)
  • Fixed bug preventing falsey params (such as ?page=0). Closes #286
  • Fixed setting of multiple cookies. Closes #199
  • Changed; view naming convention is now NAME.TYPE.ENGINE (for example page.html.haml)
  • Changed; session cookie is now httpOnly
  • Changed; Request is no longer global
  • Changed; Event is no longer global
  • Changed; “sys” module is no longer global
  • Changed; moved Request#download to Static plugin where it belongs
  • Changed; Request instance created before body parsing. Closes #262
  • Changed; Pre-caching views in memory when “cache view contents” is enabled. Closes #253
  • Changed; Pre-caching view partials in memory when “cache view partials” is enabled
  • Updated support to node —version 0.1.90
  • Updated dependencies
  • Removed set(“session cookie”) in favour of use(Session, { cookie: { … }})
  • Removed utils.mixin(); use Object#mergeDeep()
Apr 14, 20106 notes
#express #haml #kiwi #nodejs
Holy Fuck I Have A Blog!

Well I officially have a blog now, for those of you who have no clue who I am my name is TJ Holowaychuk and I work for Ext JS. I love open source! I have over 170 followers on Github and roughly 50 open source projects ranging from JavaScript, Ruby, PHP, to C and C++.

Currently my most popular open source libraries are the following:

  • JSpec JavaScript BDD framework
  • Express NodeJS web development framework inspired by Sinatra
  • JavaScript implementations of Haml and Sass
  • Kiwi package management for NodeJS

I have a thing for lexing & parsing, and am currently working on a top secret programming language named “Jade” which takes the best from my favorite languages and combines them into one sexy, fast, powerful package.

I also wrote Advanced JavaScript which is a 60 page eBook, for only $4 (holy shit!! give me money!).

I plan on blogging about a variety of topics, so if you are interested in any of the following, subscribe!!!

  • JavaScript / NodeJS / SSJS
  • Ruby / C / C++
  • Language Implementation
  • jQuery
  • Ext JS
  • Bash
  • System Administration
  • nginx
  • performance
  • CSS / design
  • HTML 5
  • GIT
Apr 14, 20108 notes
Next page →
2012 2013
  • January
  • February 3
  • March
  • April
  • May
  • June
  • July
  • August
  • September
  • October
  • November
  • December
2011 2012 2013
  • January 2
  • February 2
  • March 4
  • April 3
  • May 2
  • June 2
  • July 4
  • August 3
  • September 1
  • October 2
  • November 1
  • December 5
2010 2011 2012
  • January
  • February 3
  • March
  • April 4
  • May 2
  • June 1
  • July 3
  • August 3
  • September 3
  • October
  • November 3
  • December 1
2010 2011
  • January
  • February
  • March
  • April 8
  • May 1
  • June 3
  • July 4
  • August 4
  • September 3
  • October
  • November 1
  • December 1