Skip to content

Instantly share code, notes, and snippets.

💭
this is dumb

Kevin Ennis kevincennis

💭
this is dumb
Block or report user

Report or block kevincennis

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View README.md

What if a package did something like this, but instead of logging to the console, they sent it back to a server?

Have you actually reviewed every dependency and every child dependency in every app you deploy?

Why are people not more scared of this?

Analytics

View prom.js
const PENDING = Symbol('PENDING');
const RESOLVED = Symbol('RESOLVED');
const REJECTED = Symbol('REJECTED');
const FULFILL = Symbol('FULFILL');
const cache = new WeakMap();
const queue = typeof setImmediate !== 'undefined' ? setImmediate : setTimeout;
class Prom {
View index.js
const dgram = require('dgram');
const socket = dgram.createSocket('udp4');
const port = 123;
const host = 'pool.ntp.org';
const data = Buffer.alloc( 48 );
// RFC 2030 header stuff...
// this all gets packed into a single byte that looks like this:
//
View coify.js
'use strict';
const co = require('co');
const toString = Object.prototype.toString;
const genTag = '[object GeneratorFunction]';
const handler = {
get( target, key, receiver ) {
const fn = target[ key ];
@kevincennis
kevincennis / c.js
Last active Sep 30, 2016
Tiny co shim
View c.js
module.exports = function( fn, ...args ) {
return new Promise( ( resolve, reject ) => {
const it = fn.apply( this, args );
const [ yay, boo ] = [ 'next', 'throw' ].map( factory );
yay();
function factory( method ) {
return function( res ) {
try {
View proxymodel.js
'use strict';
const Model = ( () => {
// event cache
const events = new WeakMap();
// proxy handler
const handler = {
@kevincennis
kevincennis / README.md
Created May 26, 2016
Proctored Node Server
View README.md

Proctored Web Server

No more confusing business logic. Now you can respond to every HTTP request personally!

Usage:

  1. npm install prompt-sync
  2. node app.js

Each incoming request will block until an actual human manually responds with a body and status code.

View README.md

The function or class passed to a Pool instance has to follow the following rules:

  1. It must be safe to call its constructor with no arguments.
  2. It must implement an initObject method.
  3. It must implement a releaseObject method.

When you're done with an object, pass it to Pool#release(), and it will be made available for re-use.

View birthday.js
// Birthday problem
// https://en.wikipedia.org/wiki/Birthday_problem
// given n possible values and a set size of k,
// determine the probability of a collision
function odds( n, k ) {
return 1 - Math.exp( -0.5 * k * ( k - 1 ) / n );
}
// given n possible values and a probability of p,
View memoize.js
function memoize( fn ) {
const map = new Map();
const key = Symbol('key');
return function() {
let item = map;
let cached = false;
for ( let i = 0; i < arguments.length; ++i ) {
let cache = item.get( arguments[ i ] );
You can’t perform that action at this time.