"Nevertheless, the fact is that there is nothing as dreamy and poetic, nothing as radical, subversive, and psychedelic, as mathematics. It is every bit as mind blowing as cosmology or physics... and allows more freedom of expression than poetry, art, or music... Mathematics is the purest of the arts, as well as the most misunderstood." -Paul Lockhart
| var fs = require('fs'), | |
| path = require('path'); | |
| Connection = require('ssh2'); | |
| var tunnelHost = process.argv[2], | |
| dest = process.argv[3], | |
| keyfile = process.argv[4]; | |
| var conn = new Connection(); |
| var x = [1,2,3,4,5,6,7,8,9,10], | |
| y = [], | |
| num; | |
| for (var i = 0, count = 5; y.length < count && i < x.length; ) { | |
| if (x[i] < 6) { | |
| i++ | |
| continue; | |
| } | |
"Occurrences in this domain are beyond the reach of exact prediction because of the variety of factors in operation, not because of any lack of order in nature." - Albert Einstein
Error handling in an asynchronous language works in a unique way and presents many challenges, some unexpected. This tutorial reviews the various error handling patterns available in node, and explains how domains can be used to improve it.
There are four main error handling patterns in node:
- Error return value
| var util = require('util'); | |
| var max = parseInt(process.argv[2], 10); | |
| var obj = (new Array(26)).reduce(function (mem, _, i) { | |
| var key = String.fromCharCode(65 + i); | |
| mem[key] = key + ' value'; | |
| return mem; | |
| }, {}); |
- Understanding node
- Core modules
- Callbacks
- Events (not written yet)
- Streams (not written yet)
- Modules and NPM (not written yet)
| var fs = require('fs'), | |
| path = require('path'), | |
| async = require('async'); | |
| function reduceDir(dir, mem, callback) { | |
| if (!callback && typeof mem === 'function') { | |
| callback = mem; | |
| mem = null; | |
| } | |
If you have comments on this or disagree about rules then please reach out to me directly. I want to hear it!
Basics
So, to get something like /etc/rc.local you can use the custom SMF import facility. (See the source
for more information about how this actually works.)
/opt is mounted out of zones/opt by default. You can create a directory /opt/custom/smf and populate it with SMF manifests. Any manifests you put in there will be imported by SmartOS when it boots. Below is an example SMF manifest that simply starts /opt/custom/bin/postboot, a self-explanatory shell script that you can use like /etc/rc.local.
Note that it would likely be better to customise and respin your own images, as putting a bunch of platform state in the zones pool undoes some of the benefits of the ramdisk platform architecture that SmartOS has.
| #!/bin/bash | |
| ROOT=$1 | |
| if [ ! -d $ROOT ]; then | |
| echo "Usage lsr [dir]" | |
| exit 1 | |
| fi | |
| if [ ! -z $2 ]; then |