Tutorial by Examples

Local hooks affect only the local repositories in which they reside. Each developer can alter their own local hooks, so they can't be used reliably as a way to enforce a commit policy. They are designed to make it easier for developers to adhere to certain guidelines and avoid potential problems dow...
This hook works similarly to the post-commit hook, but it's called whenever you successfully check out a reference with git checkout. This could be a useful tool for clearing out your working directory of auto-generated files that would otherwise cause confusion. This hook accepts three parameters:...
This hook is called immediately after the commit-msg hook. It cannot alter the outcome of the git commit operation, therefore it's used primarily for notification purposes. The script takes no parameters, and its exit status does not affect the commit in any way.
This hook is called after a successful push operation. It is typically used for notification purposes. The script takes no parameters, but is sent the same information as pre-receive via standard input: <old-value> <new-value> <ref-name>
This hook is executed every time you run git commit, to verify what is about to be committed. You can use this hook to inspect the snapshot that is about to be committed. This type of hook is useful for running automated tests to make sure the incoming commit doesn't break existing functionality of...
This hook is called after the pre-commit hook to populate the text editor with a commit message. This is typically used to alter the automatically generated commit messages for squashed or merged commits. One to three arguments are passed to this hook: The name of a temporary file that contains ...
This hook is called before git rebase begins to alter code structure. This hook is typically used for making sure a rebase operation is appropriate. This hook takes 2 parameters: the upstream branch that the series was forked from, and the branch being rebased (empty when rebasing the current b...
This hook is executed every time somebody uses git push to push commits to the repository. It always resides in the remote repository that is the destination of the push and not in the originating (local) repository. The hook runs before any references are updated. It is typically used to enforce a...
This hook is called after pre-receive, and it works the same way. It's called before anything is actually updated, but is called separately for each ref that was pushed rather than all of the refs at once. This hook accepts the following 3 arguments: name of the ref being updated, old object na...
git diff branch1..branch2
This program illustrates how one can copy a file using readable and writable streams using the createReadStream(), and createWriteStream() functions provided by the file system module. //Require the file System module var fs = require('fs'); /* Create readable stream to file in current direc...
Sometimes it might be necessary to manually promisify a callback function. This could be for a case where the callback does not follow the standard error-first format or if additional logic is needed to promisify: Example with fs.exists(path, callback): var fs = require('fs'); var existsAsync =...
This is your cluster.js: const cluster = require('cluster'); const http = require('http'); const numCPUs = require('os').cpus().length; if (cluster.isMaster) { // Fork workers. for (let i = 0; i < numCPUs; i++) { cluster.fork(); } cluster.on('exit', (worker, code, signal)...
Sometimes you just need a diff to apply using patch. The regular git --diff does not work. Try this instead: git diff --no-prefix > some_file.patch Then somewhere else you can reverse it: patch -p0 < some_file.patch
var express = require('express'); var cors = require('cors'); // Use cors module for enable Cross-origin resource sharing var app = express(); app.use(cors()); // for all routes var port = process.env.PORT || 8080; app.get('/', function(req, res) { var info = { 'string_value...
You can also reference an object to publicly export and continuously append methods to that object: const auth = module.exports = {} const config = require('../config') const request = require('request') auth.email = function (data, callback) { // Authenticate with an email address } au...
Node.js has 3 basic ways to handle exceptions/errors: try-catch block error as the first argument to a callback emit an error event using eventEmitter try-catch is used to catch the exceptions thrown from the synchronous code execution. If the caller (or the caller's caller, ...) used try/ca...
In Terminal on your Mac operating system, enter the following 2 commands: lsbom -f -l -s -pf /var/db/receipts/org.nodejs.pkg.bom | while read f; do sudo rm /usr/local/${f}; done sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /var/db/receipts/org.nodejs.*
INSTALLATION PROCESS You can install Node Version Manager using git, curl or wget. You run these commands in Terminal on Mac OSX. curl example: curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.3/install.sh | bash wget example: wget -qO- https://raw.githubusercontent.com/creatio...
It's a regular pattern in design these days to vertically align call to actions inside its containing cards like this: This can be achieved using a special trick with flexbox HTML <div class="cards"> <div class="card"> <p>Lorem ipsum Magna proident ...

Page 363 of 1336