Skip to content

Instantly share code, notes, and snippets.

View ankur-anand's full-sized avatar
💭
Seize The Day!

Ankur Anand ankur-anand

💭
Seize The Day!
View GitHub Profile
@ankur-anand
ankur-anand / go-channels-1-generator.go
Created November 14, 2016 13:49 — forked from kachayev/go-channels-1-generator.go
Channels-driven concurrency with Go
// Channels-driven concurrency with Go
// Code examples from Rob Pike's talk on Google I/O 2012:
// http://www.youtube.com/watch?v=f6kdp27TYZs&feature=youtu.be
//
// Concurrency is the key to designing high performance network services.
// Go's concurrency primitives (goroutines and channels) provide a simple and efficient means
// of expressing concurrent execution. In this talk we see how tricky concurrency
// problems can be solved gracefully with simple Go code.
// (1) Generator: function that returns the channel
@ankur-anand
ankur-anand / concurrency-in-go.md
Created November 14, 2016 13:50 — forked from kachayev/concurrency-in-go.md
Channels Are Not Enough or Why Pipelining Is Not That Easy
@ankur-anand
ankur-anand / flash-app.js
Created September 19, 2017 19:03 — forked from brianmacarthur/flash-app.js
Flash messaging in Express 4: express-flash vs. custom middleware in ejs, handlebars, or jade
var express = require('express');
var cookieParser = require('cookie-parser');
var session = require('express-session');
var flash = require('express-flash');
var handlebars = require('express-handlebars')
var app = express();
var sessionStore = new session.MemoryStore;
// View Engines

Part 1: Why bubbling is good

We start with the following code

function startListening(server, cb) {
  server.listen(99999, 'localhost', cb)
}

Post Mortem Debugging in NodeJS in the Light of Promises

Context:

we're discussing how we can safely abort on unhandled rejections and obtain meaningful debugging information. Related reading: https://gist.github.com/misterdjules/2969aa1b5e6440a7e401#file-post-mortem-debugging-with-promises-md.

In particular, we're discussing https://gist.github.com/misterdjules/2969aa1b5e6440a7e401#removing-implicit-trycatch-blocks-from-v8s-promises-implementation

Othe recommended reading: On unhandledRejection https://gist.github.com/benjamingr/0237932cee84712951a2

@ankur-anand
ankur-anand / gist:68677c9a0d74aa65d0869c42b3fecd86
Created March 13, 2018 18:31 — forked from benjamingr/gist:0237932cee84712951a2
Promise unhandled rejection tracking global handler hook

Possibly Unhandled Rejection NodeJS Promise Hook

###Unhandled Rejection Tracking

Several promise libraries such as bluebird and when as well as some native promise implementations offer potentially unhandled rejection tracking. This means that the following:

Promise.reject(new Error("err")); // never attach a `catch`
@ankur-anand
ankur-anand / 1-promise-error-handling.md
Created March 13, 2018 18:41 — forked from domenic/1-promise-error-handling.md
Proposal for promise error handling hooks

Promise Error Handling Hooks

Problem

A common desire in web programming is to log any uncaught exceptions back to the server. The typical method for doing this is

window.onerror = (message, url, line, column, error) => {
  // log `error` back to the server
};
@ankur-anand
ankur-anand / ultimate-ut-cheat-sheet.md
Created March 23, 2018 07:41 — forked from yoavniran/ultimate-ut-cheat-sheet.md
The Ultimate Unit Testing Cheat-sheet For Mocha, Chai and Sinon

The Ultimate Unit Testing Cheat-sheet

For Mocha, Chai and Sinon

using mocha/chai/sinon for node.js unit-tests? check out my utility: mocha-stirrer to easily reuse test components and mock require dependencies


@ankur-anand
ankur-anand / cpu.js
Created April 7, 2018 17:46 — forked from bag-man/cpu.js
How to calculate the current CPU load with Node.js; without using any external modules or OS specific calls.
var os = require("os");
//Create function to get CPU information
function cpuAverage() {
//Initialise sum of idle and time of cores and fetch CPU info
var totalIdle = 0, totalTick = 0;
var cpus = os.cpus();
//Loop through CPU cores