Skip to content

Instantly share code, notes, and snippets.

View kevincennis's full-sized avatar
💭
this is dumb

Kevin Ennis kevincennis

💭
this is dumb
View GitHub Profile
@kevincennis
kevincennis / has-dynamic-import.js
Created November 21, 2017 20:08
dynamic import feature detection
function hasDynamicImport() {
try {
const f = new Function( 'x', 'return import("foo")' );
return true;
} catch ( err ) {
if ( err instanceof SyntaxError ) {
return false;
}
return true;
}
@kevincennis
kevincennis / tinyquery.js
Last active November 21, 2017 00:41
Tiny jQuery Starter
function $( selector, ctx = document ) {
if ( !( this instanceof $ ) ) {
return new $( selector, ctx );
}
return this.push( ...ctx.querySelectorAll( selector ) );
}
$.prototype = {
length: 0,

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

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 {
@kevincennis
kevincennis / index.js
Last active February 1, 2017 05:19
ntp client
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:
//
@kevincennis
kevincennis / coify.js
Created October 19, 2016 15:35
Proxy coify
'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 September 30, 2016 13:10
Tiny co shim
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 {
@kevincennis
kevincennis / proxymodel.js
Last active May 18, 2018 14:39
ProxyModel.js
'use strict';
const Model = ( () => {
// event cache
const events = new WeakMap();
// proxy handler
const handler = {
@kevincennis
kevincennis / README.md
Created May 26, 2016 23:59
Proctored Node Server

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.

@kevincennis
kevincennis / README.md
Last active March 29, 2016 00:17
Object Pool

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.