Skip to content

Instantly share code, notes, and snippets.

@trevorstarick
Created July 2, 2015 19:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trevorstarick/8a98abdd5ea5f6ea3149 to your computer and use it in GitHub Desktop.
Save trevorstarick/8a98abdd5ea5f6ea3149 to your computer and use it in GitHub Desktop.
var request = require('request');
var cheerio = require('cheerio');
function lorem(page, cb) {
request.get(page, function(e, r, b) {
var $ = cheerio.load(b);
return cb($('p').text());
});
}
function ipsum(para, len, cb) {
para = para.toLowerCase();
para = para.replace(/[\'\n\.\(\)]/g, '');
var ara = para.split(' ');
var docu = [];
for (var p = 0; p < len[0]; p += 1) {
docu[p] = [];
for (var s = 0; s < len[1]; s += 1) {
docu[p][s] = [];
for (var w = 0; w < len[2]; w += 1) {
var i = Math.floor(Math.random() * ara.length);
var b = Math.floor(Math.random() * 3);
if (b === 0) {
w = w;
} else if (b === 1) {
w = w + len[1];
} else if (b === 2) {
w = w - len[1];
} else {
w = w;
}
if (ara[i].length) docu[p][s].push(ara[i]);
}
}
}
docu.forEach(function(v, i, a) {
docu[i].forEach(function(v, f, a) {
docu[i][f] = docu[i][f].join(' ');
docu[i][f] = docu[i][f].charAt(0).toUpperCase() + docu[i][f].slice(1);
docu[i][f] += '.';
if(f === a.length -1) {
docu[i] = docu[i].join(' ');
}
});
});
console.log(docu.join('\n\n'));
// return cb(docu.join('\n '));
}
var url = 'https://www.compose.io/articles/coming-in-postgresql-9-5/';
// [para, sentance, words, deviation]
var length = [4, 3, 24, 8];
lorem(url, function(sed) {
ipsum(sed, length, function(text) {
console.log(text);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment