Skip to content

Instantly share code, notes, and snippets.

View stephband's full-sized avatar

stephband stephband

View GitHub Profile
@stephband
stephband / focus.js
Last active February 5, 2021 13:27
Log activeElement on focus
document.addEventListener('focusin', (e) =>
// Sanity check for target being activeElement, should always be true
console.log('focusin', e.target === document.activeElement, document.activeElement)
);
document.addEventListener('focusout', (e) =>
// Sanity check that activeElement is body, should always be true
console.log('focusout', document.body === document.activeElement)
);
@stephband
stephband / tweet-promoters.csv
Created February 13, 2018 17:40
A list of twitter accounts that promote tweets. You can import them to your blocklist at https://twitter.com/settings/blocked, choose "Advanced options".
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
948185325142024192
141671778
1595919655
859375579
1310776698
3017785207
628899279
888323120
4802917600
308660195
@stephband
stephband / overload-by-type.js
Last active August 29, 2015 14:27
Overload a function according to the types of arguments passed in
// Overload a function according to the types of arguments passed in:
//
// var fn = overloadByTypes({
// 'object': function(object) {},
// 'string number': function(string, number) {},
// 'default': function() {}
// });
//
// Returns the result of the called function. To return this to create
// a chainable method, for example, pass in true as a second argument:
// Viterbi algorithm for finding hidden relationships
function Viterbi(data) {
var V = [{}];
var path = {};
// Initialize base cases (t == 0)
for(var i=0;i<data.states.length;i++) {
var state = data.states[i];
V[0][state] = data.start_probability[state] * data.emission_probability[state][data.observations[0]];
path[state] = [state];
@stephband
stephband / jQuery.support.continuousScrollEvents.js
Last active April 9, 2016 14:44
Feature detect devices that send continuous scroll events. Typically fails on iOS, which only sends scroll events after a scroll gesture has come to rest.
(function(jQuery) {
var win = jQuery(window);
var sampleLength = 20;
var maxInterval = 250;
var avgInterval = 35;
var timeStamps = [];
function diff(n, i, array) {
return array[i + 1] - n;
}
@stephband
stephband / slideshow.js
Created August 6, 2012 10:07
Automatic slides cycling for Bolt
(function(jQuery, undefined){
// Cycle news slides
jQuery(document).ready(function(){
var slides = jQuery('.header_slide'),
length = slides.length,
i = slides.index(slides.filter('.active')[0]),
durationShort = 8000,
durationLong = 48000,
timer, fn;
@stephband
stephband / rAF.js
Created May 25, 2012 14:10 — forked from paulirish/rAF.js
requestAnimationFrame polyfill
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
// requestAnimationFrame polyfill by Erik Möller
// fixes from Paul Irish and Tino Zijdel
(function() {
var lastTime = 0;
var vendors = ['ms', 'moz', 'webkit', 'o'];
for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
@stephband
stephband / jQuery.addEasing
Created December 12, 2011 18:06
Add easing functions to jQuery based on the CSS spec for transition timing functions.
// jQuery.addEasing(string)
//
// Interprets and adds easing functions to jQuery.easing
// according to the CSS spec for transition timing functions.
//
// e.g.
// jQuery.addEasing('cubic-bezier(0.4, 0.2, 0.66, 1)');
(function(jQuery, undefined){
@stephband
stephband / gist:955477
Created May 4, 2011 16:03 — forked from jakearchibald/gist:955241
OCD in action
.whatever {
-webkit-box-shadow: 0 2px 2px rgba(0,0,0,0.5) inset;
-moz-box-shadow: 0 2px 2px rgba(0,0,0,0.5) inset;
-o-box-shadow: 0 2px 2px rgba(0,0,0,0.5) inset;
box-shadow: 0 2px 2px rgba(0,0,0,0.5) inset;
}