Skip to content

Instantly share code, notes, and snippets.

@tylerpaige
tylerpaige / custom-waiting-event.js
Last active August 26, 2015 18:24
Many browser handle the HTML media event "waiting" differently... To me, it seems this event should fire when media has been paused to allow for buffering. This function will supply that event with a fair amount of accuracy.
/* This function leverages the more cross-browser compatible event `timeupdate`
to see if the currentTime value has changed since the media supposedly starting
playing. The `timeupdate` event fires ~3/second, so every half second, we check
if the currentTime has indeed changed. If it hasn't we trigger a jQuery custom event
See this issue on the video.js repo for more information regarding this bug:
https://github.com/videojs/video.js/issues/1318 */
function listenForWaiting(media) {
var waiting = false;
@tylerpaige
tylerpaige / get-post-parameters.js
Created June 16, 2016 18:31
get or set URL parameters with replaceState
/*
GETs and POSTs URL parameters
handleParam('get', ['key', 'foo'])
> { 'key' : 'value', 'foo' : 'bar'}
handleParam('post', {'key':'value', 'foo': bar})
*/
function handleParam(method, data){
@tylerpaige
tylerpaige / stripes-sass-function.scss
Last active January 25, 2017 22:41
Sass function: Given a list of colors, generates an evenly spaced striped gradient
@function stripes($list) {
$value : ();
@for $i from 1 through length($list) {
$color : nth($list, $i);
$start : 100% / length($list) * ($i - 1);
$end : 100% / length($list) * $i;
$rampSegment : $color $start, $color $end;
$value : append($value, $rampSegment, comma);
}
@return linear-gradient($value);
@tylerpaige
tylerpaige / standardize-by-key.js
Created April 13, 2017 19:40
Take an array of objects, and standardize a specific property's value.
/*
Standardize data set so that variations of a value can be lumped together with the same property value.
This function will overwrite properties... Maybe it would be better for it to add a new field.
@param data {object} an array of objects that will be sorted
@param key {string} the object property to test in every record in the data array
@param rules {object} an object of arrays defining which values can be combined
@param combineRest {boolean} whether or not to combined records that do not match any rules
⤷ if true, all records that do not match a rule will have their property `key` set to `"other"`
⤷ if false, all records that do not match a rule will maintain their existing property `key`
@tylerpaige
tylerpaige / frame-count-reduction.sh
Last active September 6, 2017 15:29
Remove every n frames of gif
#!/bin/bash
# This script will remove every n frames an GIF
# Usage: ./frame-count-reduction.sh input.gif n output.gif
input=$1
divider=$2
output=$3
numOfFrames=eval gifsicle master.gif -I | grep -E -o "[0-9]+ images" | grep -E -o "[0-9]+"
numOfFramesInclusive=$((numOfFrames - 1))
@tylerpaige
tylerpaige / index.html
Created April 5, 2018 16:23
Valid RGBA checker
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="Valid RGBA checker">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>

Keybase proof

I hereby claim:

  • I am tylerpaige on github.
  • I am tylerpaige (https://keybase.io/tylerpaige) on keybase.
  • I have a public key ASAyBwNW8rsyyGyacHHqGLSl0Ha-KTdjz8DlZYQ9hqhyvgo

To claim this, I am signing this object:

const delayedReturn = (i) => {
return new Promise((resolve, reject) => {
setTimeout(() => {
console.log(i);
resolve(i);
}, 1000);
});
};
async function* stepSerial(count) {
@tylerpaige
tylerpaige / get-subdirectories.js
Created January 3, 2019 19:05
get an array of subfolders given a path
const { promisify } = require('util');
const readFile = promisify(fs.readFile);
const lstat = promisify(fs.lstat);
const readDir = promisify(fs.readdir);
const isDirectory = source => {
return lstat(source).then(stats =>
Promise.resolve(stats.isDirectory() ? source : false)
);
};
const path = require('path')
const getAllFiles = (dir, ext = '.js') => {
return readDir(dir).then(children => {
return children
.filter(fileName => {
const fileExtension = path.extname(fileName);
return fileExtension.includes(ext);
})
.map(fileName => path.resolve(dir, fileName));