Skip to content

Instantly share code, notes, and snippets.

View trentmwillis's full-sized avatar

Trent Willis trentmwillis

View GitHub Profile
import { useEffect, useRef } from 'react';
/**
* A small utility hook to help figure out what is changing and causing
* re-renders. Add it to the component you're investigating and pass in a object
* of the values that you think might be changing.
*
* Ex: useWhatChanged({ someProp, someOtherProp });
*/
export function useWhatChanged(props) {
@trentmwillis
trentmwillis / .bash_profile
Created August 20, 2018 20:13
Bash Aliases
# Git
alias gs="git status"
alias gc="git checkout"
alias gcb="git checkout -b"
alias gb="git branch"
alias gprom="git pull --rebase origin master"
alias gprum="git pull --rebase upstream master"
alias gl="git log"
alias glp="git log --decorate --pretty=oneline"
@trentmwillis
trentmwillis / ember-testing.js
Created April 6, 2017 16:29
fixing ember-testing.js
(function() {
/*!
* @overview Ember - JavaScript Application Framework
* @copyright Copyright 2011-2017 Tilde Inc. and contributors
* Portions Copyright 2006-2011 Strobe Inc.
* Portions Copyright 2008-2011 Apple Inc. All rights reserved.
* @license Licensed under MIT license
* See https://raw.github.com/emberjs/ember.js/master/LICENSE
* @version 2.14.0-alpha.1-ember-testing+df839ae1
*/
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
@trentmwillis
trentmwillis / asset-loader.js
Last active July 19, 2016 16:57
Ember Asset Loading Service
import RSVP from 'rsvp';
import Ember from 'ember';
const RETRY_LOAD = Symbol('RETRY_LOAD');
function createLoadElement(tag, load, error) {
const el = document.createElement(tag);
el.onload = load;
el.onerror = error;
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle'
});
@trentmwillis
trentmwillis / qunit-before-after.js
Created August 28, 2015 15:49
Adds `before` and `after` hooks to QUnit to enable one-time setup and teardown steps. Similar to Mocha.
// Add the `before` hook
QUnit.moduleStart(function() {
// QUnit is weird in that once a module starts, it is considered the `previousModule` and not the `currentModule`.
let previousModule = QUnit.config.previousModule;
let testEnvironment = previousModule && previousModule.testEnvironment;
let before = testEnvironment && testEnvironment.before;
// If the module has a `before` function, call it with the `testEnvironment` as the context.
if (before && typeof before === 'function') {
before.call(testEnvironment);
@trentmwillis
trentmwillis / snowflakes
Created December 13, 2014 00:01
A simple script to make falling snow on any page
(function() {
var snowflakes = [],
moveAngle = 0,
animationInterval;
/**
* Generates a random number between the min and max (inclusive).
* @method getRandomNumber
* @param {Number} min
* @param {Number} max
@trentmwillis
trentmwillis / plax
Created August 17, 2014 01:16
A simple parallax effect on scroll
var Plax = function() {
var plax = document.querySelectorAll('.plax');
for (var i=0; i<plax.length; i++) {
plax[i].style.position = 'fixed';
}
document.onscroll = function() {
for (var i=0; i<plax.length; i++) {
plax[i].style.top = (-plax[0].getAttribute('data-plax') * document.body.scrollTop) + 'px';
@trentmwillis
trentmwillis / disappear-on-scroll
Created June 27, 2014 04:44
Co-worker prank. Ya know, just for fun
document.onscroll = function() {
document.body.style.transition = 'opacity 1s';
document.body.style.opacity = '0';
}