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 / 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 / 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 / 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 / jsbin.soxawi.css
Last active September 30, 2015 22:31 — forked from rwjblue/jsbin.oxasil.css
JSBin for Ember.js test setup with QUnit (http://jsbin.com/soxawi/edit)
#ember-testing-container {
position: absolute;
background: white;
bottom: 0;
right: 0;
width: 640px;
height: 384px;
overflow: auto;
z-index: 9999;
border: 1px solid #ccc;
@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 / ember-component-bubble-action.js
Created December 16, 2014 01:21
"bubble" action for all Ember components which sends the given action
Ember.Component.reopen({
actions: {
bubble: function (action) {
console.log('[Component action.bubble]', arguments);
var temp = this.get(action);
this.set(action, action);
this.sendAction(action);
this.set(action, temp);