super-chatty. helpful for debugging, and probably nothing else
debug "this is a debugging message"
| var EventEmitter2 = require('eventemitter2').EventEmitter2; | |
| var a = new EventEmitter2({wildcard: true}); | |
| a.onAny(function(foo, bar) { | |
| console.log(this.event, foo, bar); | |
| }); | |
| a.emit('a', 1, 2); | |
| // logs a 1 2 | |
| // Is there a more elegant way of forwarding all events from one |
| var es = require('event-stream'); | |
| function makeThing() { | |
| var out = es.through(); | |
| var substream = es.through(); | |
| substream.pipe(out); | |
| setInterval(function() { | |
| substream.write('internal data\n'); | |
| }, 200); |
| var Stream = require('stream'); | |
| var a = new Stream; | |
| a.pipe(process.stdout); | |
| a.emit('data', 'omg test 123\n'); | |
| // logs: omg test 123 | |
| var b = new Stream; | |
| b.pipe(a); | |
| b.emit('data', 'omg test 456\n'); |
| var Stream = require('stream'); | |
| var logStream = new Stream; | |
| logStream.pipe(process.stdout); | |
| var progress = {}; | |
| var prefix; | |
| var msgMaxlen; | |
| var msgLast; | |
| progress.start = function(p) { |
| // http://benalman.com/grab/a1eec0.png | |
| String.prototype.peencode = function() { | |
| return this.replace(/\w/g, "x").replace(/\b\w/g, "8").replace(/\w\b/g, "D").replace(/x/g, "="); | |
| }; | |
| $.getScript("https://rawgithub.com/cowboy/jquery-replacetext/master/jquery.ba-replacetext.js", function() { | |
| $("*").replaceText(/.*/g, function(s) { return s.peencode(); }); | |
| }); |
| // An object with a property and a method. | |
| var obj = { | |
| name: "Ben", | |
| logName: function() { | |
| console.log(this.name); | |
| } | |
| }; | |
| // And another global variable, for good measure. | |
| var name = "Whoops"; |
| // Re. https://github.com/umdjs/umd/blob/master/returnExportsGlobal.js | |
| // ================================================== | |
| // Q. Does all that UMD stuff need to be at the top? | |
| // ================================================== | |
| (function (root, factory) { | |
| if (typeof exports === 'object') { | |
| // Node. Does not work with strict CommonJS, but | |
| // only CommonJS-like enviroments that support module.exports, |
| // I saw an example like this, but I don't like the nesting. | |
| getThing().then(function(thing) { | |
| return when.all(thing.ids.map(function(id) { | |
| return getSubThing(id); | |
| })).then(function(subthings) { | |
| // doSomething(thing, subthings); | |
| }); | |
| }); | |
| // Can `thing` be passed to when.all and this the next .then() ? |
| // todo: find way to load jQuery into a FB page without getting the "Refused to | |
| // load the script because it violates the following Content Security Policy" error | |
| // step 1 | |
| document.getElementById("webMessengerRecentMessages").innerHTML | |
| // step 2 | |
| $(".-cx-PRIVATE-uiImageBlock__content").each(function() { | |
| var name = $(this).find(".-cx-PRIVATE-webMessengerMessageGroup__authorName").text(); | |
| $(this).find(".-cx-PRIVATE-webMessengerMessageGroup__message p").each(function() { |