-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update format of node-for-everyday-things.
- Loading branch information
1 parent
baca343
commit 2381ca5
Showing
8 changed files
with
76 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[submodule "articles/step-of-conductor/step"] | ||
path = articles/step-of-conductor/step | ||
url = git://github.com/creationix/step.git | ||
[submodule "articles/step-of-conductor/conductor"] | ||
path = articles/step-of-conductor/conductor | ||
url = git://github.com/creationix/conductor.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/usr/bin/env node | ||
/** | ||
* Calculate the approximate the number of "pages" in a text document based on | ||
* a word count of 350 words per page. | ||
*/ | ||
|
||
var sys = require('sys'), | ||
fs = require('fs'); | ||
|
||
/* Include some instructions for when I forget how this works. */ | ||
function USAGE(message) { | ||
var error_code = 0; | ||
sys.puts("\n USAGE: pagecount FILENAME\n\n" + | ||
" Show the estimated page count of a file based on 350 words per page.\n" + | ||
" FILENAME should be the name of a utf-8 encoded text file.\n" + | ||
"\b\n" + | ||
" Example:\n\t\tpagecount MyFile.txt\n\n Estimates the page count of MyFile.txt\n"); | ||
|
||
if (message !== undefined) { | ||
sys.puts(message); | ||
error_code = 1; | ||
} | ||
process.exit(error_code); | ||
}; | ||
|
||
/* PageCount() analyze the file and displays the results */ | ||
function PageCount(filename) { | ||
fs.stat(filename, function (stat_error, stat) { | ||
if (stat_error) { | ||
USAGE("ERROR: " + filename + ", " + stat_error); | ||
} | ||
|
||
if (stat.isFile()) { | ||
fs.readFile(filename, 'utf8', function (read_error, content) { | ||
var subtotal_words = 0; | ||
if (read_error) { | ||
USAGE("ERROR: Can't read " + filename + ". " + read_error); | ||
} | ||
/* Replace all non-letter characters with a single space. */ | ||
subtotal_words = content.replace(/\W+|\s+/gm,' ').split(' ').length; | ||
page_count = (subtotal_words/350); | ||
if (Number(page_count).toFixed(0) <= 1) { | ||
sys.puts(filename + "(" + subtotal_words + " words): " + | ||
Number(page_count * 100).toFixed(0) + "% of one page."); | ||
} else { | ||
sys.puts(filename + "(" + subtotal_words + " words):" + | ||
Number(page_count).toFixed(2) + " pages."); | ||
} | ||
}); | ||
} else { | ||
USAGE("ERROR: " + filename + " is not a file."); | ||
} | ||
}); | ||
}; | ||
|
||
if (process.argv.length < 3) { | ||
USAGE(); | ||
} | ||
|
||
/* For each file I want to tally up call PageCount() */ | ||
for (var i = 2; i < process.argv.length; i += 1) { | ||
PageCount(process.argv[i]); | ||
} |
Submodule conductor
added at
c00ff7
Binary file not shown.
Submodule step
added at
d63ae6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
var Step = require('step') | ||
var Step = require('step'); | ||
|
||
Step( | ||
function loadData() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters