This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** For use in testing only */ | |
export const resetExecutionHistory = () => { | |
Object.keys(executionHistory).forEach(key => delete executionHistory[key]) | |
} | |
/** | |
* Specifies when a class or function has an execution dependency on another | |
* function or class. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Adds callbacks to an element's style changes. | |
* Useful if you need to make changes right before and/or right | |
* after an element recieves a style change. | |
* @param el Element | |
* @param hooks Pre and post style change callbacks | |
*/ | |
export const addStyleHooks = ( | |
el: HTMLElement, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type FuncOfUnknownArgs<ReturnType> = (...args: Array<any>) => ReturnType | |
const cache = <ReturnType>(fn: FuncOfUnknownArgs<ReturnType>): FuncOfUnknownArgs<ReturnType> => { | |
let cachedVal: ReturnType | |
/** Don't trust cache val to be truthy */ | |
let hasCached = false | |
return function (...args: Array<any>) { | |
if (!hasCached) { | |
hasCached = true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"nl": { | |
"default": { | |
"heading": "Wij geven om uw privacy", | |
"details1": { | |
"text1": "Wij en", | |
"link1": "onze partners", | |
"purpose1": "Informatie op een apparaat opslaan en / of openen" | |
}, | |
"details2": { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Find all style and link/stylesheet tags. | |
* Request all the css from link tags. | |
* Parse through all the style and css text. | |
* Find any min-width or max-width within parentheses. | |
* Log out a key of each min/max width and a count of how | |
* often it was used. | |
*/ | |
const getAllBreakpoints = () => { | |
const styleTexts = [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function insertScript(script: HTMLScriptElement, callback?: Function) { | |
const firstScript = document.getElementsByTagName( | |
'script' | |
)[0] as HTMLScriptElement | |
const parentNode = firstScript.parentNode as HTMLElement | |
const errorMessage = `Error loading asset ${script.getAttribute('src')}` | |
parentNode.insertBefore(script, firstScript) | |
script.addEventListener('load', () => (callback ? callback() : null)) | |
script.addEventListener('error', () => | |
callback ? callback(errorMessage) : null |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import TimedFunction from '../TimedFunction' | |
describe('Timed Function', () => { | |
let func | |
let timedFunction: TimedFunction | |
beforeEach(() => { | |
func = jest.fn() | |
// speed this shit up | |
TimedFunction.tickRate = 100 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* I'd been working on getting this pattern just right for adding common behaviors to class-based React components. | |
* The last hiccup I had was getting the state and props to inherit correctly from a mixin into a superclass and this | |
* appears to finally work as expected. | |
*/ | |
import * as React from 'react' | |
type Component<P, S, T = React.Component<P, S>> = new (...args: any[]) => T |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def have_correct_change?(desired_total, your_coins) | |
possible_arrangements = your_coins.count | |
for_all(possible_arrangements) do |a_possible_arrangement| | |
return true if correct_change_can_be_made?(desired_total, a_possible_arrangement, your_coins) | |
end | |
false | |
end | |
def correct_change_can_be_made?(desired_total, arrangement, your_coins) | |
possible_combos_in_an_arrangement = all_combinations_of(arrangement, your_coins) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def change_calculator(total, change_array) | |
change_array.length.times do |iteration| | |
combinations = change_array.combination(iteration) | |
combinations.each do |combo| | |
return true if (combo.inject(:+)) == total | |
end | |
end | |
return false | |
end |
NewerOlder