Skip to content

Instantly share code, notes, and snippets.

💭
Working on @ToDesktop

Dave Jeffery davej

💭
Working on @ToDesktop
Block or report user

Report or block davej

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View keybase.md

Keybase proof

I hereby claim:

  • I am davej on github.
  • I am davej (https://keybase.io/davej) on keybase.
  • I have a public key ASCGM6pZ2DMI-QNgpHyOlpPARpMxaK5PQI2eJIkwfMxiwwo

To claim this, I am signing this object:

@davej
davej / finished-polyfill.js
Last active Aug 29, 2019 — forked from simevidas/finished-polyfill.js
Animation.prototype.finished polyfill
View finished-polyfill.js
// only polyfill .finished in browsers that already support animate()
if (document.body.animate) {
// Chrome does not seem to expose the Animation constructor globally
if (typeof Animation === 'undefined') {
window.Animation = document.body.animate({}).constructor;
}
if (!('finished' in Animation.prototype)) {
Object.defineProperty(Animation.prototype, 'finished', {
@davej
davej / prevent-idle.py
Created Dec 23, 2017
Prevent Mid 2014 MBP random shutdown
View prevent-idle.py
# From https://discussions.apple.com/thread/8115237
from time import sleep
while True:
sleep(0.00002)
@davej
davej / isLocalhost.js
Created Apr 9, 2017
Detect if current hostname is local
View isLocalhost.js
const isLocalhostName = window.location.hostname === 'localhost';
const isLocalhostIPv6 = window.location.hostname === '[::1]';
const isLocalhostIPv4 = window.location.hostname.match(
// 127.0.0.1/8
/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/
);
const isLocalhost = isLocalhostName || isLocalhostIPv6 || isLocalhostIPv4;
@davej
davej / fetch-timeout.js
Last active Sep 16, 2019
Add a pseudo timeout/deadline to a request using the ES6 fetch api
View fetch-timeout.js
Promise.race([
fetch('/foo'),
new Promise((_, reject) =>
setTimeout(() => reject(new Error('Timeout')), 7000)
)
]);
@davej
davej / onScrollYChange.js
Last active Sep 12, 2016
Performant scroll change listener
View onScrollYChange.js
// Your scroll callback will only be called once per frame and only
// when the y-position changes. Good for doing DOM work without causing
// unnecessary reflows of the document.
function onScrollYChange(callback) {
let latestKnownScrollY = 0, ticking = false;
const scrollChanged = () => {
ticking = false;
const currentScrollY = latestKnownScrollY;
callback(currentScrollY)
@davej
davej / optionDefaults.js
Last active Jul 25, 2016
Options object merged with defaults in ES2015+
View optionDefaults.js
function createSite(name, assignedOptions = {}) {
const defaultOptions = {
html: 'jade',
styles: 'scss',
scripts: 'babel',
whitespace: '2 spaces',
};
const options = Object.assign({}, defaultOptions, assignedOptions);
/*
@davej
davej / transitionToPromise.js
Last active Mar 18, 2019
Do a CSS transition and resolve promise when complete
View transitionToPromise.js
const transitionToPromise = (el, property, value) =>
new Promise(resolve => {
el.style[property] = value;
const transitionEnded = e => {
if (e.propertyName !== property) return;
el.removeEventListener('transitionend', transitionEnded);
resolve();
}
el.addEventListener('transitionend', transitionEnded);
});
View gist:c697978bf61ff4e47317
Verifying that +davej is my Bitcoin username. You can send me #bitcoin here: https://onename.io/davej
View gist:49b25fa90f75c7615919
extendsScope_module = angular.module 'classy-extends', ['classy-core']
###
Note that this does NOT get the mixin class dependencies as of now.
###
extendsScope_module.classy.plugin.controller
name: 'extends'
localInject: ['$controller']
You can’t perform that action at this time.