Skip to content

Instantly share code, notes, and snippets.

View pwfisher's full-sized avatar

Patrick Fisher pwfisher

View GitHub Profile
@pwfisher
pwfisher / ScrollToHack.tsx
Created November 23, 2021 07:20
ScrollToHack: scrollTo override — disable calls without "allowed" arg or property. Next.js History.scrollRestoration debug tool.
import { FC, useEffect } from 'react'
type ScrollToOptionsPlusAllowed = ScrollToOptions & { allowed: boolean }
/**
* Hack to completely disable Next.js emulation of History.scrollRestoration.
* Everywhere we want to scroll, we must add `allowed: true`.
* @see https://github.com/vercel/next.js/issues/20951#issuecomment-970710409
*/
export const ScrollToHack: FC = () => {
@pwfisher
pwfisher / local-storage-service-test.js
Last active April 20, 2021 19:43
Ember service:local-storage trivial wrapper for window.localStorage
import { moduleFor } from 'ember-qunit'
import test from 'dummy/tests/ember-sinon-qunit/test'
moduleFor('service:local-storage')
const mockStore = { setItem() { }, removeItem() { } }
test('when localStorage throws an exception', function testCatch(assert) {
const service = this.subject()
const stub = this.stub(mockStore, 'setItem').throws()
@pwfisher
pwfisher / fastboot-watch-notifier.js
Last active April 20, 2021 19:34
Ember fastboot-app-server notifier which polls for filesystem events to restart server. Polls to support use within virtual machines (e.g. Vagrant vm dev box with NFS mounted source).
const debounce = require('debounce')
const FastBootAppServer = require('fastboot-app-server')
const Sane = require('sane')
const distPath = '/app/dist'
const server = new FastBootAppServer({
distPath,
notifier: {
subscribe(notify) {
@pwfisher
pwfisher / gtm-util.js
Last active April 20, 2021 19:32
Ember.js Google Tag Manager utility
// Google Tag Manager
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s);j.async=true;j.src=
'//www.googletagmanager.com/gtm.js?id='+i;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-ABCDEF');
// End Google Tag Manager
App.GtmUtil = {
@pwfisher
pwfisher / optimizely-client.d.ts
Created April 20, 2021 19:02
Optimizely Client Side Types
/**
* @see https://docs.developers.optimizely.com/web/docs
*
* globalThis.optimizely?.get('state').getVariationMap()
* {
* 20015858428: { id: "20020533131", name: null, index: null },
* 20104572923: { id: "20121934640", name: "v1", index: 0 },
* }
*/
@pwfisher
pwfisher / template-string-replacement-token-syntax.md
Last active March 23, 2021 22:02
Template string replacement token syntax -- compare and contrast conventions in lovable libraries and languages

Python

def greet(name):
    return f"Hello, {name}!"
greet('Fred')

Mustache

Mustache.render("Hello, {{name}}!", { name: 'Fred' });
@pwfisher
pwfisher / adapters.product.js
Last active November 23, 2016 02:23
Payload race condition
import DS from 'ember-data';
export default DS.RESTAdapter.extend({
buildURL() {
return 'https://products.dollarshaveclub.com/cms/edge/v3/products.json';
},
});
@pwfisher
pwfisher / dynamic-alias.js
Last active August 2, 2016 20:20
Implementation of the missing "Ember.computed.dynamicAlias"
import Ember from 'ember';
// @see http://emberjs.jsbin.com/beboga/edit?js,output
export default function dynamicAlias(target, keyKey) {
var prefix = target ? `${target}.` : '';
var dynamicAliasKey = `${prefix}${keyKey}_alias`;
return Ember.computed(function() {
var key = `${prefix}${this.get(keyKey)}`;
Ember.defineProperty(this, dynamicAliasKey, Ember.computed.alias(key));
@pwfisher
pwfisher / scroll-to-me.js
Created March 16, 2015 23:11
Ember.js "scroll-to-me" component (scrolls window to itself on didInsertElement)
import Ember from 'ember';
export default Ember.Component.extend({
didInsertElement: function () {
Ember.$('html, body').animate({ scrollTop: this.$().offset().top }, '2000');
}
});
@pwfisher
pwfisher / jquery.nodoubletapzoom.js
Created July 27, 2012 08:39 — forked from johan/jquery.nodoubletapzoom.js
A jQuery plugin to selectively disable the iOS double-tap-to-zoom action on specific page elements (and have that generate two click events instead).
// jQuery no-double-tap-zoom plugin
// Triple-licensed: Public Domain, MIT and WTFPL license - share and enjoy!
(function($) {
var IS_IOS = /iphone|ipad/i.test(navigator.userAgent);
$.fn.nodoubletapzoom = function() {
if (IS_IOS)
$(this).bind('touchstart', function preventZoom(e) {
var now = (new Date().getTime()),