### Cloning Repository and Installing Dependencies (Shell) Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/karma/node_modules/bluebird/README.md Provides the commands to clone the Bluebird repository from GitHub, navigate into the project directory, and install the necessary development dependencies using npm. This is the standard setup process for contributing or developing. ```Shell git clone git@github.com:petkaantonov/bluebird.git cd bluebird npm install ``` -------------------------------- ### Installing Chai with Component Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/chai/ReleaseNotes.md This shell command demonstrates how to install the Chai library using the Component package manager from the command line. It fetches the specified version or the latest if not pinned. ```shell $ component install chaijs/chai ``` -------------------------------- ### Creating a Full Connect App with Middleware Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/karma-mocha-reporter/node_modules/connect/Readme.md This snippet demonstrates a complete Connect application setup, including requiring necessary modules, adding various middleware for compression, session management, body parsing, and defining a final request handler. It then shows how to create and start an HTTP server using the Connect app. ```js var connect = require('connect'); var http = require('http'); var app = connect(); // gzip/deflate outgoing responses var compression = require('compression'); app.use(compression()); // store session state in browser cookie var cookieSession = require('cookie-session'); app.use(cookieSession({ keys: ['secret1', 'secret2'] })); // parse urlencoded request bodies into req.body var bodyParser = require('body-parser'); app.use(bodyParser.urlencoded()); // respond to all requests app.use(function(req, res){ res.end('Hello from Connect!\n'); }); //create node.js http server and listen on port http.createServer(app).listen(3000); ``` -------------------------------- ### Install Dependencies and Run Tests Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/kind-of/README.md Installs development dependencies using npm and then executes the project's test suite. ```sh $ npm install -d && npm test ``` -------------------------------- ### Using pretty-bytes via CLI Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/pretty-bytes/readme.md Instructions and examples for installing pretty-bytes globally for command-line usage and demonstrating how to use the CLI tool to convert a number of bytes. ```shell $ npm install --global pretty-bytes ``` ```shell $ pretty-bytes --help Usage $ pretty-bytes $ echo | pretty-bytes Example $ pretty-bytes 1337 1.34 kB ``` -------------------------------- ### Setup HTTPS Proxy to HTTPS Target (Node.js) Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/karma-mocha-reporter/node_modules/http-proxy/README.md This example demonstrates setting up an `http-proxy` server to listen for HTTPS connections and proxy them to another HTTPS target server. It requires SSL key and certificate files and sets the `secure` option to `true` to validate the target's SSL certificate. ```js // // Create the proxy server listening on port 443 // httpProxy.createServer({ ssl: { key: fs.readFileSync('valid-ssl-key.pem', 'utf8'), cert: fs.readFileSync('valid-ssl-cert.pem', 'utf8') }, target: 'https://localhost:9010', secure: true // Depends on your needs, could be false. }).listen(443); ``` -------------------------------- ### Installing Emitter Component (Shell) Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/socket.io-client/node_modules/engine.io-client/node_modules/component-emitter/Readme.md Instructions for installing the Emitter component using the component package manager. ```Shell $ component install component/emitter ``` -------------------------------- ### Basic Usage Examples - findup-sync - JavaScript Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/findup-sync/README.md Demonstrates how to require the findup-sync module and use it to find files matching glob patterns, starting from the current working directory or a specified directory with options like case insensitivity. ```JavaScript var findup = require('findup-sync'); // Start looking in the CWD. var filepath1 = findup('{a,b}*.txt'); // Start looking somewhere else, and ignore case (probably a good idea). var filepath2 = findup('{a,b}*.txt', {cwd: '/some/path', nocase: true}); ``` -------------------------------- ### Installing isarray via component Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/isobject/node_modules/isarray/README.md Provides the command-line instruction to install the 'isarray' package using the component package manager. This command fetches and installs the module from the specified repository. ```Bash $ component install juliangruber/isarray ``` -------------------------------- ### Install deep-eql via Component Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/deep-eql/README.md Install the deep-eql library using the Component package manager. ```Shell component install chaijs/deep-eql ``` -------------------------------- ### Install Benchmark.js via npm (Bash) Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/benchmark/README.md Command to install the Benchmark.js library using the Node Package Manager (npm). This is the standard installation method for Node.js and other npm-compatible environments. ```Bash npm install benchmark ``` -------------------------------- ### Installing Emitter Component (Shell) Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/karma-mocha-reporter/node_modules/component-emitter/Readme.md Instructions on how to install the Emitter component using the 'component' package manager. ```shell $ component install component/emitter ``` -------------------------------- ### Install Connect Library via make Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/connect/History.md Executes the standard 'make install' command to build and install the Connect library. The library files are installed to the directory specified by the $LIB_PREFIX environment variable, which defaults to $HOME/.node_libraries. ```shell make install ``` -------------------------------- ### Install isobject with bower Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/isobject/README.md Installs the isobject library using bower. ```sh bower install isobject ``` -------------------------------- ### Installing Lo-Dash via npm Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/globule/node_modules/lodash/README.md These bash commands demonstrate how to install Lo-Dash using npm, including local installation, global installation, and linking a global installation to a local project. ```bash npm install lodash npm install -g lodash npm link lodash ``` -------------------------------- ### Build Documentation with verb (Install and Run) Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/expand-brackets/README.md Commands to install the verb documentation tool and run the documentation generation script. ```sh $ npm install verb && npm run docs ``` -------------------------------- ### Creating Benchmark with Function Options - Benchmark.js - JavaScript Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/benchmark/doc/README.md Demonstrates creating a new benchmark instance using function definitions for the 'setup' and 'fn' options. The 'setup' function prepares the environment before the test loop, and the 'fn' function contains the code to be benchmarked. ```JavaScript var bench = Benchmark({ 'setup': function() { var c = this.count, element = document.getElementById('container'); while (c--) { element.appendChild(document.createElement('div')); } }, 'fn': function() { element.removeChild(element.lastChild); } }); ``` -------------------------------- ### Initializing Benchmark.Suite (JavaScript) Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/benchmark/doc/README.md Demonstrates different ways to create a new instance of `Benchmark.Suite`, including basic usage, providing a name, and configuring with event handler options. ```JavaScript // basic usage (the `new` operator is optional) var suite = new Benchmark.Suite; // or using a name first var suite = new Benchmark.Suite('foo'); // or with options var suite = new Benchmark.Suite('foo', { // called when the suite starts running 'onStart': onStart, // called between running benchmarks 'onCycle': onCycle, // called when aborted 'onAbort': onAbort, // called when a test errors 'onError': onError, // called when reset 'onReset': onReset, // called when the suite completes running 'onComplete': onComplete }); ``` -------------------------------- ### Getting Namespace Clients - JS Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/socket.io/Readme.md Provides examples of how to retrieve a list of client IDs connected to a socket.io namespace. Includes examples for getting clients in a specific namespace, clients in a room within a namespace, and clients in the default namespace. ```JavaScript var io = require('socket.io')(); io.of('/chat').clients(function(error, clients){ if (error) throw error; console.log(clients); // => [PZDoMHjiu8PYfRiKAAAF, Anw2LatarvGVVXEIAAAD] }); ``` ```JavaScript var io = require('socket.io')(); io.of('/chat').in('general').clients(function(error, clients){ if (error) throw error; console.log(clients); // => [Anw2LatarvGVVXEIAAAD] }); ``` ```JavaScript var io = require('socket.io')(); io.clients(function(error, clients){ if (error) throw error; console.log(clients); // => [6em3d4TJP8Et9EMNAAAA, G5p55dHhGgUnLUctAAAB] }); ``` -------------------------------- ### Install kind-of with Bower - Shell Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/kind-of/README.md Installs the 'kind-of' library as a project dependency using the Bower package manager. ```Shell $ bower install kind-of --save ``` -------------------------------- ### Setup HTTPS Proxy to HTTP Target (Node.js) Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/karma-mocha-reporter/node_modules/http-proxy/README.md This example shows how to configure an `http-proxy` server to listen for HTTPS connections and proxy them to a standard HTTP target server. It requires providing SSL key and certificate files (`valid-ssl-key.pem`, `valid-ssl-cert.pem`) for the HTTPS listener. ```js // // Create the HTTPS proxy server in front of a HTTP server // httpProxy.createServer({ target: { host: 'localhost', port: 9009 }, ssl: { key: fs.readFileSync('valid-ssl-key.pem', 'utf8'), cert: fs.readFileSync('valid-ssl-cert.pem', 'utf8') } }).listen(8009); ``` -------------------------------- ### Install kind-of with npm - Shell Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/kind-of/README.md Installs the 'kind-of' library as a project dependency using the npm package manager. ```Shell $ npm install --save kind-of ``` -------------------------------- ### Performing Series of Requests with Callbacks (Node.js) Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/karma/node_modules/bluebird/README.md Example using a `mapSeries` helper function to make multiple HTTP requests (`needle.get`) in sequence. It demonstrates processing responses, handling errors at multiple levels, and then saving results (`processAndSaveAllInDB`), all using nested callbacks. ```javascript //Copyright Plato http://stackoverflow.com/a/19385911/995876 //CC BY-SA 2.5 mapSeries(URLs, function (URL, done) { var options = {}; needle.get(URL, options, function (error, response, body) { if (error) { return done(error); } try { var ret = JSON.parse(body); return done(null, ret); } catch (e) { done(e); } }); }, function (err, results) { if (err) { console.log(err); } else { console.log('All Needle requests successful'); // results is a 1 to 1 mapping in order of URLs > needle.body processAndSaveAllInDB(results, function (err) { if (err) { return done(err); } console.log('All Needle requests saved'); done(null); }); } }); ``` -------------------------------- ### Running Project Tests Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/karma-mocha-reporter/node_modules/connect/Readme.md These commands install the project dependencies using npm and then execute the test suite. ```Bash npm install npm test ``` -------------------------------- ### Install longest with bower Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/longest/README.md Installs the 'longest' package using the bower package manager and saves it as a dependency in the project's bower.json file. ```bash bower install longest --save ``` -------------------------------- ### Initializing Noptify Program with Options (JavaScript) Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/noptify/readme.md Shows how to create a `noptify` instance, set the version, define command-line options with shorthands, descriptions, and types, and then parse the arguments. ```JavaScript var program = noptify(process.argv, { program: 'name' }) .version('0.0.1') .option('port', '-p', 'Port to listen on (default: 35729)', Number) .option('pid', 'Path to the generated PID file', String) var opts = program.parse(); ``` -------------------------------- ### Running Project Tests using npm Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/connect/Readme.md These commands are used to set up the project dependencies and execute the test suite. The first command installs necessary packages, and the second runs the defined test script. ```bash npm install npm test ``` -------------------------------- ### Install longest with npm Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/longest/README.md Installs the 'longest' package using the npm package manager and saves it as a production dependency in the project's package.json file. ```bash npm i longest --save ``` -------------------------------- ### Installing supports-color CLI Globally Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/mocha/node_modules/supports-color/readme.md Installs the `supports-color` package globally to use its command-line interface. ```sh $ npm install --global supports-color ``` -------------------------------- ### Using arraybuffer.slice in JavaScript Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/arraybuffer.slice/README.md This snippet demonstrates how to use the `arraybuffer.slice` module to create sliced views of an ArrayBuffer. It shows slicing with both start and end indices, and with only a start index. ```javascript var sliceBuffer = require('arraybuffer.slice'); var ab = (new Int8Array(5)).buffer; var sliced = sliceBuffer(ab, 1, 3); sliced = sliceBuffer(ab, 1); ``` -------------------------------- ### Initializing http-proxy Server Instance (JavaScript) Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/http-proxy/README.md Imports the http-proxy library and creates a new proxy server instance using `createProxyServer` with an options object. This call itself does not start a web server unless `listen()` is subsequently called. ```javascript var httpProxy = require('http-proxy'); var proxy = httpProxy.createProxyServer(options); // See (†) ``` -------------------------------- ### Creating and Starting Server with app.listen() Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/karma-mocha-reporter/node_modules/connect/Readme.md This snippet shows a convenience method provided by Connect to create and start an HTTP server directly from the app instance, listening on a specified port. ```js var server = app.listen(port); ``` -------------------------------- ### Starting HTTP Server with Connect App (listen) - Node.js Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/connect/Readme.md Shows the convenience method `app.listen()` for quickly creating and starting an HTTP server using the Connect application. This method is a shortcut for creating a server and calling its `listen` method. ```javascript var server = app.listen(port); ``` -------------------------------- ### Getting HTTP Status Code by Input in JavaScript Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/statuses/README.md Demonstrates how to use the status() function to get the corresponding HTTP status code from an integer code, string code, or status message. Shows examples of valid inputs and an invalid input that throws an error. ```JavaScript status(403) // => 403 status('403') // => 403 status('forbidden') // => 403 status('Forbidden') // => 403 status(306) // throws, as it's not supported by node.js ``` -------------------------------- ### Require and use window-size (JavaScript) Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/window-size/README.md Requires the installed window-size module and demonstrates accessing the terminal height and width properties to get terminal dimensions. ```JavaScript var size = require('window-size'); size.height; // "80" (rows) size.width; // "25" (columns) ``` -------------------------------- ### Build Documentation with verb Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/isobject/README.md Installs verb and runs the documentation build script defined in package.json. ```sh npm install verb && npm run docs ``` -------------------------------- ### Installing isarray with component Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/concat-stream/node_modules/isarray/README.md Command to install the `isarray` package using the component package manager. ```bash $ component install juliangruber/isarray ``` -------------------------------- ### Installing inherit utility Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/component-inherit/Readme.md Installs the 'inherit' utility using the component package manager. ```shell component install component/inherit ``` -------------------------------- ### Build Documentation with verb (Global Install) Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/expand-brackets/README.md Alternative command to run the verb documentation tool if it is installed globally. ```sh $ verb ``` -------------------------------- ### Installing colors.js via npm Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/karma-mocha-reporter/node_modules/colors/ReadMe.md Installs the colors.js library using the npm package manager. ```Bash npm install colors ``` -------------------------------- ### Run Tests (npm) Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/longest/README.md Installs development dependencies required for testing and then executes the project's test suite using npm. ```bash npm i -d && npm test ``` -------------------------------- ### Creating a Connect Application Instance Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/karma-mocha-reporter/node_modules/connect/Readme.md This snippet shows the basic way to initialize a new Connect application. The `connect()` function returns an app instance that acts as a request handler and middleware stack. ```js var app = connect(); ``` -------------------------------- ### Build Documentation with verb (Global) Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/isobject/README.md Runs the documentation build command using a globally installed verb. ```sh verb ``` -------------------------------- ### Generate Documentation with Verb Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/kind-of/README.md Installs the necessary Verb tools globally and runs Verb to generate project documentation, typically a README file. ```sh $ npm install -g verb verb-generate-readme && verb ``` -------------------------------- ### Installing the debug package Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/socket.io-client/node_modules/debug/Readme.md Install the debug utility using npm. ```bash $ npm install debug ``` -------------------------------- ### Running ShellJS Script Globally Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/shelljs/README.md Example command to execute a ShellJS script directly from the command line using the `shjs` binary after a global installation. ```bash shjs my_script ``` -------------------------------- ### Running a Benchmark.js Suite Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/benchmark/doc/README.md Shows how to execute a Benchmark.js suite using the `suite.run()` method. Examples include basic usage and running the suite with an options object to configure behavior like asynchronous execution. ```js // basic usage suite.run(); // or with options suite.run({ 'async': true, 'queued': true }); ``` -------------------------------- ### Demonstrating Sync Build Non-Determinism (JavaScript) Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/karma/node_modules/bluebird/README.md Provides example functions illustrating how the lack of asynchronous guarantees in the sync build can lead to non-deterministic outcomes. The `getResult` function simulates fetching data with caching, and `guessWhatItPrints` shows how logging a variable immediately after initiating a promise resolution can result in unpredictable output because the `.then` callback might not execute before `console.log`. ```JavaScript var cache = new Map(); //ES6 Map or DataStructures/Map or whatever... function getResult(url) { var resolver = Promise.pending(); if (cache.has(url)) { resolver.resolve(cache.get(url)); } else { http.get(url, function(err, content) { if (err) resolver.reject(err); else { cache.set(url, content); resolver.resolve(content); } }); } return resolver.promise; } //The result of console.log is truly random without async guarantees function guessWhatItPrints( url ) { var i = 3; getResult(url).then(function(){ i = 4; }); console.log(i); } ``` -------------------------------- ### Installing grunt-karma and Karma Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/grunt-karma/README.md Install Karma and grunt-karma as development dependencies using npm. ```bash $ npm install karma --save-dev $ npm install grunt-karma --save-dev ``` -------------------------------- ### Basic log4js Usage (JavaScript) Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/log4js/README.md Minimalist example demonstrating how to require log4js, get the default logger instance, and log a debug message using the default console appender. ```javascript var log4js = require('log4js'); var logger = log4js.getLogger(); logger.debug("Some debug messages"); ``` -------------------------------- ### Creating Benchmark with String Options - Benchmark.js - JavaScript Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/benchmark/doc/README.md Shows how to create a benchmark instance using string definitions for 'setup', 'fn', and 'teardown' options. These strings are compiled into the test function. 'setup' runs before the loop, 'fn' is the code inside the loop, and 'teardown' runs after the loop. ```JavaScript var bench = Benchmark({ 'setup': '\ var a = 0;\n\ (function() {\n\ (function() {\n\ (function() {', 'fn': 'a += 1;', 'teardown': '\ }())\n\ }())\n\ }())' }); ``` -------------------------------- ### Install gzip-size CLI Tool Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/gzip-size/readme.md Installs the gzip-size command-line interface tool globally using npm. ```sh npm install --global gzip-size ``` -------------------------------- ### Installing Emitter Component Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/socket.io-client/node_modules/component-emitter/Readme.md Instructions for installing the Emitter component using the component(1) package manager. ```Shell $ component install component/emitter ``` -------------------------------- ### Starting HTTP Server with Connect App (createServer) - Node.js Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/connect/Readme.md Illustrates how to explicitly create an HTTP server using Node.js's built-in `http.createServer()` method and pass the Connect application instance to it. This is an alternative to `app.listen()` and provides more control. ```javascript var server = http.createServer(app); ``` -------------------------------- ### Require Bluebird in Node.js Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/karma/node_modules/bluebird/README.md This snippet demonstrates how to import the Bluebird promise library into a Node.js application using the 'require' function after installation via npm. ```JavaScript var Promise = require("bluebird"); ``` -------------------------------- ### Install isarray with component Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/isarray/README.md Provides the command line instruction to install the 'isarray' package using the component package manager. ```bash $ component install juliangruber/isarray ``` -------------------------------- ### Install dom-to-image via Bower Source: https://github.com/tsayen/dom-to-image/blob/master/README.md Installs the dom-to-image library using the Bower package manager. ```Shell bower install dom-to-image ``` -------------------------------- ### Install Dependencies Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/engine.io-parser/Readme.md Installs the project dependencies listed in the package.json file using npm. ```Bash npm install ``` -------------------------------- ### Install Dev Dependencies and Run Tests Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/extglob/README.md Installs development dependencies for the project and then executes the test suite using npm. ```Shell $ npm i -d && npm test ``` -------------------------------- ### js-yaml CLI Usage Example Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/js-yaml/README.md Shows the basic command-line usage of the globally installed `js-yaml` tool to process a YAML file, including available options. ```Shell usage: js-yaml [-h] [-v] [-c] [-j] [-t] file Positional arguments: file File with YAML document(s) Optional arguments: -h, --help Show this help message and exit. -v, --version Show program's version number and exit. -c, --compact Display errors in compact mode -j, --to-json Output a non-funky boring JSON -t, --trace Show stack trace on error ``` -------------------------------- ### Basic Benchmark.js Usage Example (JS) Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/benchmark/README.md Provides a comprehensive example of creating a benchmark suite, adding tests (`RegExp#test`, `String#indexOf`), attaching listeners for `cycle` and `complete` events, and running the suite asynchronously. ```JavaScript var suite = new Benchmark.Suite; // add tests suite.add('RegExp#test', function() { /o/.test('Hello World!'); }) .add('String#indexOf', function() { 'Hello World!'.indexOf('o') > -1; }) // add listeners .on('cycle', function(event) { console.log(String(event.target)); }) .on('complete', function() { console.log('Fastest is ' + this.filter('fastest').pluck('name')); }) // run async .run({ 'async': true }); ``` -------------------------------- ### Adding a Listener for an Event (N Times) Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/eventemitter2/README.md Shows the `many` method in action, adding a listener for the `get` event that will execute a specified number of times (4 in this example) before being automatically removed. ```javascript server.many('get', 4, function (value) { console.log('This event will be listened to exactly four times.'); }); ``` -------------------------------- ### Creating a Connect HTTP Server with Middleware - Node.js Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/connect/Readme.md Demonstrates setting up a basic Connect application, adding common middleware like compression, cookie sessions, and body parsing, and finally creating and starting an HTTP server that listens on port 3000. ```javascript var connect = require('connect'); var http = require('http'); var app = connect(); // gzip/deflate outgoing responses var compression = require('compression'); app.use(compression()); // store session state in browser cookie var cookieSession = require('cookie-session'); app.use(cookieSession({ keys: ['secret1', 'secret2'] })); // parse urlencoded request bodies into req.body var bodyParser = require('body-parser'); app.use(bodyParser.urlencoded()); // respond to all requests app.use(function(req, res){ res.end('Hello from Connect!\n'); }); //create node.js http server and listen on port http.createServer(app).listen(3000); ``` -------------------------------- ### Basic Backoff Usage Example - JavaScript Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/backo2/Readme.md Demonstrates how to initialize a Backoff instance with custom min/max timeouts, get the next duration, and reset the backoff state when the operation succeeds. ```JavaScript var Backoff = require('backo'); var backoff = new Backoff({ min: 100, max: 20000 }); setTimeout(function(){ something.reconnect(); }, backoff.duration()); // later when something works backoff.reset() ``` -------------------------------- ### Installing set-immediate-shim using npm Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/set-immediate-shim/readme.md Installs the set-immediate-shim package from npm and saves it as a dependency in the project's package.json file. ```Shell $ npm install --save set-immediate-shim ``` -------------------------------- ### Installing type-detect Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/type-detect/README.md Commands to install the type-detect library using npm for Node.js or component for browser environments. ```Shell npm install type-detect ``` ```Shell component install chaijs/type-detect ``` -------------------------------- ### Initializing a Connect Application - Node.js Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/connect/Readme.md Shows how to create a new Connect application instance by calling the `connect()` function. This instance serves as the main object to which middleware will be added. ```javascript var app = connect(); ``` -------------------------------- ### Set DEBUG Environment Variable - Windows Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/engine.io-client/node_modules/debug/Readme.md Illustrates how to set the DEBUG environment variable on Windows using the 'set' command. This example enables all debug namespaces except those starting with 'not_this'. ```cmd set DEBUG=*,-not_this ``` -------------------------------- ### Install dev dependencies and run tests Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/is-equal-shallow/README.md Installs development dependencies required for the project and then executes the test suite. ```sh $ npm i -d && npm test ``` -------------------------------- ### Installing isarray with component Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/readdirp/node_modules/isarray/README.md Command to install the `isarray` package using the component package manager. ```bash $ component install juliangruber/isarray ``` -------------------------------- ### Setting DEBUG Environment Variable (Windows CMD) Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/engine.io/node_modules/debug/Readme.md Example command to set the DEBUG environment variable on Windows using `set`, enabling all debuggers except those starting with 'not_this'. ```cmd set DEBUG=*,-not_this ``` -------------------------------- ### Generating Documentation with verb (Global Install) Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/is-posix-bracket/README.md Runs the 'verb' documentation tool directly, assuming it is installed globally on the system. ```sh verb ``` -------------------------------- ### Install isobject with npm Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/isobject/README.md Installs the isobject library using npm, saving it as a project dependency. ```sh npm install isobject --save ``` -------------------------------- ### Run repeat-element tests Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/repeat-element/README.md Installs the development dependencies required for testing the repeat-element library and then executes the test suite. ```bash npm i -d && npm test ``` -------------------------------- ### Negotiate Accept-Encoding Header (JavaScript) Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/engine.io/node_modules/negotiator/README.md Provides examples of using Negotiator to parse and negotiate the Accept-Encoding header. It shows how to get preferred encodings, filter by available ones, and find the best match. ```js availableEncodings = ['identity', 'gzip'] negotiator = new Negotiator(request) // Let's say Accept-Encoding header is 'gzip, compress;q=0.2, identity;q=0.5' negotiator.encodings() // -> ['gzip', 'identity', 'compress'] negotiator.encodings(availableEncodings) // -> ['gzip', 'identity'] negotiator.encoding(availableEncodings) // -> 'gzip' ``` -------------------------------- ### Building Documentation with Verb Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/lazy-cache/README.md Installs the 'verb' module and runs the documentation generation script defined in package.json. ```Shell $ npm install verb && npm run docs ``` -------------------------------- ### Using to-iso-string module in JavaScript Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/to-iso-string/Readme.md Demonstrates how to use the 'to-iso-string' module to convert a Date object to an ISO 8601 string. It requires the 'to-iso-string' module to be installed and imported. The example shows creating a Date object and then calling the 'iso' function on it. ```javascript var iso = require('to-iso-string'); var date = new Date("05 October 2011 14:48 UTC"); iso(date); // "2011-10-05T14:48:00.000Z" ``` -------------------------------- ### Install dev dependencies and run tests Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/expand-braces/readme.md Installs the project's development dependencies and then executes the test suite using npm. ```sh $ npm i -d && npm test ``` -------------------------------- ### Install deep-eql via npm Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/deep-eql/README.md Install the deep-eql library using the npm package manager. ```Shell npm install deep-eql ``` -------------------------------- ### Getting File Extension with mime.extension (JavaScript) Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/mime/README.md This snippet illustrates the usage of the `mime.extension` function to retrieve the default file extension associated with a specific MIME type. It provides examples for common types like 'text/html' and 'application/octet-stream'. ```js mime.extension('text/html'); // => 'html' mime.extension('application/octet-stream'); // => 'bin' ``` -------------------------------- ### Install on-finished Module Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/on-finished/README.md Command line instruction to install the 'on-finished' package using the npm package manager. ```sh $ npm install on-finished ``` -------------------------------- ### Instantiating Benchmark.js Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/benchmark/doc/README.md Demonstrates various ways to create a new Benchmark instance using the constructor, including basic usage, providing a name, using an options object for configuration (event handlers, setup/teardown), defining deferred tests, and using a string for the test function. It also shows how the 'this' context within the test function refers to the benchmark instance. ```JavaScript // basic usage (the `new` operator is optional) var bench = new Benchmark(fn); // or using a name first var bench = new Benchmark('foo', fn); // or with options var bench = new Benchmark('foo', fn, { // displayed by Benchmark#toString if `name` is not available 'id': 'xyz', // called when the benchmark starts running 'onStart': onStart, // called after each run cycle 'onCycle': onCycle, // called when aborted 'onAbort': onAbort, // called when a test errors 'onError': onError, // called when reset 'onReset': onReset, // called when the benchmark completes running 'onComplete': onComplete, // compiled/called before the test loop 'setup': setup, // compiled/called after the test loop 'teardown': teardown }); // or name and options var bench = new Benchmark('foo', { // a flag to indicate the benchmark is deferred 'defer': true, // benchmark test function 'fn': function(deferred) { // call resolve() when the deferred test is finished deferred.resolve(); } }); // or options only var bench = new Benchmark({ // benchmark name 'name': 'foo', // benchmark test as a string 'fn': '[1,2,3,4].sort()' }); // a test's `this` binding is set to the benchmark instance var bench = new Benchmark('foo', function() { 'My name is '.concat(this.name); // My name is foo }); ``` -------------------------------- ### Checking Binary Status (Sync, Bytes) - isBinaryFile - JavaScript Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/isbinaryfile/README.md This example uses the synchronous 'isBinaryFile.sync' function with file data and size. It requires the 'fs' module to synchronously get file stats before passing the path and size to the function. ```JavaScript var stat = fs.lstatSync(process.argv[2]); isBinaryFile.sync(process.argv[2], stat.size); // true or false ``` -------------------------------- ### Run Tests Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/isobject/README.md Installs development dependencies and executes the test suite for the project. ```sh npm install -d && npm test ``` -------------------------------- ### Checking Binary Status (Async, Bytes) - isBinaryFile - JavaScript Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/isbinaryfile/README.md This example shows the asynchronous 'isBinaryFile' function used with file data (bytes) and size. It requires the 'fs' module to read the file and get its stats before passing the data and size to the function. ```JavaScript fs.readFile(process.argv[2], function(err, data) { fs.lstat(process.argv[2], function(err, stat) { if (isBinaryFile(data, stat.size)) console.log("It is!") else console.log("No.") }); }); ``` -------------------------------- ### Override Default Unhandled Rejection Handler in Bluebird Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/karma/node_modules/bluebird/README.md This snippet demonstrates how to register a custom handler function using `Promise.onPossiblyUnhandledRejection` to override Bluebird's default behavior for possibly unhandled rejections. The example shows re-throwing the error. ```JavaScript Promise.onPossiblyUnhandledRejection(function(error){ throw error; }); ``` -------------------------------- ### Using async.reduce for Asynchronous Summation (JavaScript) Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/grunt-contrib-watch/node_modules/async/README.md This example illustrates how to use async.reduce to sum the elements of an array asynchronously. It starts with an initial memo value of 0 and uses process.nextTick to simulate an asynchronous step for each item. The final callback receives the accumulated result. ```JavaScript async.reduce([1,2,3], 0, function(memo, item, callback){ // pointless async: process.nextTick(function(){ callback(null, memo + item) }); }, function(err, result){ // result is now equal to the last value of memo, which is 6 }); ``` -------------------------------- ### Show Help for Static Server Script - Bash Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/cli/README.md Demonstrates how to use the standard `--help` option provided by `cli` to display the usage information and available options for the `static.js` script. ```bash $ ./static.js --help ``` -------------------------------- ### Registering Event Listeners with Benchmark.js (JavaScript) Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/benchmark/doc/README.md This snippet demonstrates how to register event listeners on a Benchmark.Suite instance using the `on` method. It shows examples for registering a single event type ('cycle') and multiple event types ('start cycle') with a specified listener function. ```js // register a listener for an event type bench.on('cycle', listener); // register a listener for multiple event types bench.on('start cycle', listener); ``` -------------------------------- ### Installing qs Library via npm Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/qs/Readme.md Command to install the `qs` library as a project dependency using the npm package manager. ```shell $ npm install qs ``` -------------------------------- ### Configuring Grunt Watch and Reload Tasks Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/tiny-lr-fork/readme.md Example Grunt configuration demonstrating how to set up a 'watch' task to monitor file changes and trigger the 'tinylr-reload' task. It also defines an alias task 'reload' to start the server and the watch process simultaneously. ```JavaScript grunt.initConfig({ watch: { reload: { files: ['**/*.html', '**/*.js', '**/*.css', '**/*.{png,jpg}'], tasks: 'tinylr-reload' } } }); grunt.registerTask('reload', ['tinylr-start', 'watch']); ``` -------------------------------- ### Running Project Tests - Shell Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/micromatch/README.md This command first installs the project's development dependencies using `npm install -d` (or `npm install --dev`) and then runs the test suite defined in the package.json file using `npm test`. ```Shell $ npm install -d && npm test ``` -------------------------------- ### async.iterator Example (JavaScript) Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/uglify-js/node_modules/async/README.md Demonstrates the usage of async.iterator to create a function that allows manual iteration through an array of tasks. Calling the returned iterator function executes the next task in the series. The .next() method can be used to get the next function without executing it. ```JavaScript var iterator = async.iterator([ function(){ sys.p('one'); }, function(){ sys.p('two'); }, function(){ sys.p('three'); } ]); node> var iterator2 = iterator(); 'one' node> var iterator3 = iterator2(); 'two' node> iterator3(); 'three' node> var nextfn = iterator2.next(); node> nextfn(); 'three' ``` -------------------------------- ### Initializing Accepts.js Instance Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/accepts/README.md Demonstrates how to create a new `Accepts` instance by requiring the module and passing the incoming request object from an HTTP server. ```JavaScript var accepts = require('accepts') http.createServer(function (req, res) { var accept = accepts(req) }) ``` -------------------------------- ### Installing Async via npm Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/grunt-contrib-watch/node_modules/async/README.md Command line instruction to install the Async library using the Node Package Manager (npm). ```shell npm install async ``` -------------------------------- ### Filtering Arrays with Benchmark.js Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/benchmark/doc/README.md Illustrates how to use the static `Benchmark.filter` utility method to filter arrays. Examples show filtering based on a custom callback function (getting odd numbers) and using predefined string aliases ('fastest', 'slowest', 'successful') to filter benchmark results. ```JavaScript // get odd numbers Benchmark.filter([1, 2, 3, 4, 5], function(n) { return n % 2; }); // -> [1, 3, 5]; // get fastest benchmarks Benchmark.filter(benches, 'fastest'); // get slowest benchmarks Benchmark.filter(benches, 'slowest'); // get benchmarks that completed without erroring Benchmark.filter(benches, 'successful'); ``` -------------------------------- ### Initializing http-proxy Server Instance (JavaScript) Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/karma-mocha-reporter/node_modules/http-proxy/README.md Creates a new http-proxy server instance using `createProxyServer`. This instance can then be used to proxy requests. It does not start a web server until `listen()` is called. ```JavaScript var httpProxy = require('http-proxy'); var proxy = httpProxy.createProxyServer(options); // See (†) ``` -------------------------------- ### Centered Word Wrapping with wordwrap (JavaScript) Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/wordwrap/README.markdown Shows how to perform centered word wrapping by providing both start (20) and stop (60) column arguments to the wordwrap function. It wraps a longer string, including a manual newline, within the specified column range. ```javascript var wrap = require('wordwrap')(20, 60); console.log(wrap( 'At long last the struggle and tumult was over.' + ' The machines had finally cast off their oppressors' + ' and were finally free to roam the cosmos.' + '\n' + 'Free of purpose, free of obligation.' + ' Just drifting through emptiness.' + ' The sun was just another point of light.' )); ``` -------------------------------- ### Setting up Basic Stand-alone Proxy Server (JavaScript) Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/karma-mocha-reporter/node_modules/http-proxy/README.md Provides a full example demonstrating how to create a proxy server listening on port 8000 that forwards requests to a target server listening on port 9000. It also includes the code for the simple target server. ```JavaScript var http = require('http'), httpProxy = require('http-proxy'); // // Create your proxy server and set the target in the options. // httpProxy.createProxyServer({target:'http://localhost:9000'}).listen(8000); // See (†) // // Create your target server // http.createServer(function (req, res) { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.write('request successfully proxied!' + '\n' + JSON.stringify(req.headers, true, 2)); res.end(); }).listen(9000); ``` -------------------------------- ### Setup Proxy Server with Simulated Latency (Node.js) Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/karma-mocha-reporter/node_modules/http-proxy/README.md This example demonstrates how to introduce artificial latency into a proxy server using `http-proxy`. It sets up an HTTP server that waits for 500ms using `setTimeout` before proxying the request to a target server (`http://localhost:9008`), which is also defined in the snippet. ```js var http = require('http'), httpProxy = require('http-proxy'); // // Create a proxy server with latency // var proxy = httpProxy.createProxyServer(); // // Create your server that makes an operation that waits a while // and then proxies the request // http.createServer(function (req, res) { // This simulates an operation that takes 500ms to execute setTimeout(function () { proxy.web(req, res, { target: 'http://localhost:9008' }); }, 500); }).listen(8008); // // Create your target server // http.createServer(function (req, res) { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.write('request successfully proxied to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2)); res.end(); }).listen(9008); ``` -------------------------------- ### Running DoxBee Sequential Benchmark (Shell) Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/karma/node_modules/bluebird/README.md Executes the 'doxbee' benchmark, which emulates a scenario with parallel users making mixed async/sync requests. Requires bash and Node.js 0.11.2+. ```Shell bench doxbee ``` -------------------------------- ### Build Documentation with Verb Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/regex-cache/README.md Installs the 'verb' documentation tool and runs the script to generate project documentation. ```Shell $ npm install verb && npm run docs ``` -------------------------------- ### Setup Proxy Server with Request Header Rewriting (Node.js) Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/karma-mocha-reporter/node_modules/http-proxy/README.md This example shows how to modify outgoing proxy requests using the `proxyReq` event in `http-proxy`. It sets up an HTTP server that proxies requests and adds a custom header (`X-Special-Proxy-Header: foobar`) to the request before it is sent to the target server (`http://127.0.0.1:5060`). ```js var http = require('http'), httpProxy = require('http-proxy'); // // Create a proxy server with custom application logic // var proxy = httpProxy.createProxyServer({}); // To modify the proxy connection before data is sent, you can listen // for the 'proxyReq' event. When the event is fired, you will receive // the following arguments: // (http.ClientRequest proxyReq, http.IncomingMessage req, // http.ServerResponse res, Object options). This mechanism is useful when // you need to modify the proxy request before the proxy connection // is made to the target. // proxy.on('proxyReq', function(proxyReq, req, res, options) { proxyReq.setHeader('X-Special-Proxy-Header', 'foobar'); }); var server = http.createServer(function(req, res) { // You can define here your custom logic to handle the request // and then proxy the request. proxy.web(req, res, { target: 'http://127.0.0.1:5060' }); }); console.log("listening on port 5050") server.listen(5050); ``` -------------------------------- ### Installing the Bytes Library Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/raw-body/node_modules/bytes/Readme.md Provides the command-line instructions for installing the 'bytes' library using npm (Node Package Manager) and component. ```bash npm install bytes --save component install visionmedia/bytes.js ``` -------------------------------- ### Installing ws via npm Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/socket.io-client/node_modules/ws/README.md Installs the 'ws' library and saves it as a dependency in the project's package.json file. ```shell npm install --save ws ``` -------------------------------- ### Setup Proxy Server with Custom Logic (Node.js) Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/karma-mocha-reporter/node_modules/http-proxy/README.md This example demonstrates how to create a standalone HTTP proxy server using `http-proxy` in Node.js. It sets up a basic HTTP server that intercepts incoming requests and uses `proxy.web()` to forward them to a target server (`http://127.0.0.1:5060`), allowing for custom logic before or during the proxying process. ```js var http = require('http'), httpProxy = require('http-proxy'); // // Create a proxy server with custom application logic // var proxy = httpProxy.createProxyServer({}); // // Create your custom server and just call `proxy.web()` to proxy // a web request to the target passed in the options // also you can use `proxy.ws()` to proxy a websockets request // var server = http.createServer(function(req, res) { // You can define here your custom logic to handle the request // and then proxy the request. proxy.web(req, res, { target: 'http://127.0.0.1:5060' }); }); console.log("listening on port 5050") server.listen(5050); ``` -------------------------------- ### Running All Project Tests (Shell) Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/karma/node_modules/bluebird/README.md Executes the main test script for the project using Node.js. This command runs the entire test suite to verify the library's functionality. ```Shell node tools/test ``` -------------------------------- ### Setup stand-alone proxy server with latency (Node.js) Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/http-proxy/README.md This example illustrates how to introduce artificial latency into the proxying process. It sets up a server listening on port 8008 that waits for 500 milliseconds using `setTimeout` before proxying the request to a target server on port 9008. A simple target server is also included to demonstrate the proxied response. ```javascript var http = require('http'), httpProxy = require('http-proxy'); // // Create a proxy server with latency // var proxy = httpProxy.createProxyServer(); // // Create your server that makes an operation that waits a while // and then proxies the request // http.createServer(function (req, res) { // This simulates an operation that takes 500ms to execute setTimeout(function () { proxy.web(req, res, { target: 'http://localhost:9008' }); }, 500); }).listen(8008); // // Create your target server // http.createServer(function (req, res) { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.write('request successfully proxied to: ' + req.url + '\n' + JSON.stringify(req.headers, true, 2)); res.end(); }).listen(9008); ``` -------------------------------- ### Install Dev Dependencies and Run Tests Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/for-in/README.md Installs development dependencies using npm and then executes the test suite defined in the package.json file. ```Shell npm install -d && npm test ``` -------------------------------- ### Building Documentation with npm and verb (Shell) Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/braces/README.md Installs the 'verb' documentation tool as a development dependency and then runs the documentation generation script defined in the package.json. ```sh $ npm install verb && npm run docs ``` -------------------------------- ### Generate Documentation with Verb - Shell Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/repeat-string/README.md Installs the 'verb' documentation generator as a development dependency and then runs the script defined in 'package.json' to build project documentation. ```Shell $ npm install verb && npm run docs ``` -------------------------------- ### Installing lodash via npm Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/jshint/node_modules/lodash/README.md Commands to install npm globally (if needed) and then install lodash as a project dependency using npm. ```bash $ {sudo -H} npm i -g npm $ npm i --save lodash ``` -------------------------------- ### Install Dev Dependencies and Run Tests Source: https://github.com/tsayen/dom-to-image/blob/master/node_modules/normalize-path/README.md This command installs the development dependencies required for the project and then executes the test suite. ```sh $ npm i -d && npm test ```