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 / flippinawesome.js
Created November 4, 2013 03:37
Better timing
var audio = new window.webkitAudioContext(),
position = 0,
scale = {
g: 392,
f: 349.23,
e: 329.63,
b: 493.88
},
song = "gfefgg-fff-gbb-gfefggggffgfe---";
@kevincennis
kevincennis / pluck.js
Last active December 6, 2019 06:04
Karplus-Strong with Web Audio API
function Pluck( ctx ) {
this.sr = ctx.sampleRate;
this.pro = ctx.createScriptProcessor( 512, 0, 1 );
this.pro.connect( ctx.destination );
}
Pluck.prototype.play = function( freq ) {
var N = Math.round( this.sr / freq ),
impulse = this.sr / 1000,
y = new Float32Array( N ),
function reverse( str ) {
if ( str.length <= 1 ) {
return str;
}
return reverse( str.substr( 1 ) ) + str[ 0 ];
}
@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 / .babelrc
Last active August 3, 2018 18:27
totp/hotp
{
"plugins": [
"transform-flow-strip-types"
]
}
@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('');
function CF() {}
CF.P1 = 'somevalue';
CF.P2 = 'somevalue';
var CFp = {
CFP1: 'somevalue'
};
CF.prototype = CFp;
@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'