Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
this is dumb

Kevin Ennis kevincennis

💭
this is dumb
View GitHub Profile
@kevincennis
kevincennis / elasticsearch.sh
Created Jan 9, 2019
Elasticsearch Codeship
View elasticsearch.sh
#!/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
View index.js
const nextTick = () => Promise.resolve();
class DataLoader {
constructor( batch ) {
this.batch = batch;
this.queue = [];
this.cache = new Map();
}
View .babelrc
{
"plugins": [
"transform-flow-strip-types"
]
}
View cfp.js
function CF() {}
CF.P1 = 'somevalue';
CF.P2 = 'somevalue';
var CFp = {
CFP1: 'somevalue'
};
CF.prototype = CFp;
@kevincennis
kevincennis / hibp.js
Last active Jul 12, 2018
haveibeenpwned password check
View hibp.js
// 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('');
View konami.js
( () => {
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
CSS string lightness
View example.js
'#ddd'.darker // '#a0a0a0'
'#ddd'.lighter // '#f0f0f0'
'#ddd'.darker.darker // '#808080'
@kevincennis
kevincennis / has-dynamic-import.js
Created Nov 21, 2017
dynamic import feature detection
View has-dynamic-import.js
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 Nov 21, 2017
Tiny jQuery Starter
View tinyquery.js
function $( selector, ctx = document ) {
if ( !( this instanceof $ ) ) {
return new $( selector, ctx );
}
return this.push( ...ctx.querySelectorAll( selector ) );
}
$.prototype = {
length: 0,