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 / example.js
Last active October 25, 2023 11:21
Async Concurrent Queue
( async() => {
const items = 'abcdefghijklmnopqrstuvwxyz'.split('');
const concurrency = 10;
async function process() {
return new Promise( r => setTimeout( r, Math.random() * 1000 ) );
}
async function report({ item, processed, total, done }){
if ( done ) {
@kevincennis
kevincennis / README.md
Created March 9, 2022 18:43
deno node compat mongo demo
npm i
deno run --unstable --compat --allow-all index.j
@kevincennis
kevincennis / elasticsearch.sh
Created January 9, 2019 00:22
Elasticsearch Codeship
#!/bin/bash
# Install a custom ElasticSearch version - https://www.elastic.co/products/elasticsearch
#
# To run this script in Codeship, add the following
# command to your project's test setup command:
# \curl -sSL https://raw.githubusercontent.com/codeship/scripts/master/packages/elasticsearch.sh | bash -s
#
# Add at least the following environment variables to your project configuration
# (otherwise the defaults below will be used).
# * ELASTICSEARCH_VERSION
@kevincennis
kevincennis / index.js
Created September 14, 2018 02:15
DataLoader
const nextTick = () => Promise.resolve();
class DataLoader {
constructor( batch ) {
this.batch = batch;
this.queue = [];
this.cache = new Map();
}
@kevincennis
kevincennis / .nvmrc
Last active July 9, 2020 17:31
GraphQL Demo
10.6.0
@kevincennis
kevincennis / .babelrc
Last active August 3, 2018 18:27
totp/hotp
{
"plugins": [
"transform-flow-strip-types"
]
}
function CF() {}
CF.P1 = 'somevalue';
CF.P2 = 'somevalue';
var CFp = {
CFP1: 'somevalue'
};
CF.prototype = CFp;
@kevincennis
kevincennis / hibp.js
Last active July 12, 2018 01:28
haveibeenpwned password check
// convert an unsigned int to hex string
const toHex = b => ( '00' + b.toString( 16 ) ).slice( -2 );
// return the SHA-1 hash of a given string
// note: crypto.subtle is unavailable on non-HTTPS pages
const sha1 = async str => {
const msg = new TextEncoder('utf-8').encode( str );
const buf = await crypto.subtle.digest( 'SHA-1', msg );
return [ ...new Uint8Array( buf ) ].map( toHex ).join('');
@kevincennis
kevincennis / konami.js
Created June 7, 2018 15:53
ultra-retro
( () => {
const expect = [ 38, 38, 40, 40, 37, 39, 37, 39, 66, 65 ];
const pressed = [];
document.addEventListener( 'keyup', e => {
pressed.push( e.keyCode );
for ( let i = 0; i < pressed.length; ++i ) {
if ( pressed[ i ] !== expect[ i ] ) {
pressed.length = 0;
@kevincennis
kevincennis / example.js
Created May 22, 2018 19:00
CSS string lightness
'#ddd'.darker // '#a0a0a0'
'#ddd'.lighter // '#f0f0f0'
'#ddd'.darker.darker // '#808080'