Skip to content

Instantly share code, notes, and snippets.

View davej's full-sized avatar
💭
Working on @ToDesktop

Dave Jeffery davej

💭
Working on @ToDesktop
View GitHub Profile
###
# To create a plugin you need to include the `classy-core` module and then pass
# your plugin object into the `class.plugin.controller function`
###
angular.module('classy-yourPlugin', ['classy-core']).classy.plugin.controller
name: 'yourPlugin'
###
# Dependencies placed in the localInject array will be available on `@` (`this`)
/*
* To create a plugin you need to include the `classy-core` module and then pass
* your plugin object into the `class.plugin.controller function`
*/
angular.module('classy-yourPlugin', ['classy-core']).classy.plugin.controller({
name: 'yourPlugin',
/*
* Dependencies placed in the localInject array will be available on `@` (`this`)
* in the plugins init and postInit methods.
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']
Verifying that +davej is my Bitcoin username. You can send me #bitcoin here: https://onename.io/davej
@davej
davej / transitionToPromise.js
Last active January 31, 2023 15:49
Do a CSS transition and resolve promise when complete
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);
});
@davej
davej / optionDefaults.js
Last active July 25, 2016 12:15
Options object merged with defaults in ES2015+
function createSite(name, assignedOptions = {}) {
const defaultOptions = {
html: 'jade',
styles: 'scss',
scripts: 'babel',
whitespace: '2 spaces',
};
const options = Object.assign({}, defaultOptions, assignedOptions);
/*
@davej
davej / onScrollYChange.js
Last active September 12, 2016 21:04
Performant scroll change listener
// 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 / fetch-timeout.js
Last active July 1, 2022 23:35
Add a pseudo timeout/deadline to a request using the ES6 fetch api
Promise.race([
fetch('/foo'),
new Promise((_, reject) =>
setTimeout(() => reject(new Error('Timeout')), 7000)
)
]);
@davej
davej / isLocalhost.js
Created April 9, 2017 11:42
Detect if current hostname is local
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 / prevent-idle.py
Created December 23, 2017 02:14
Prevent Mid 2014 MBP random shutdown
# From https://discussions.apple.com/thread/8115237
from time import sleep
while True:
sleep(0.00002)