Skip to content

Instantly share code, notes, and snippets.

View JamieDixon's full-sized avatar

Jamie Dixon JamieDixon

View GitHub Profile
<Response>
<Say voice="alice">Thanks for trying our documentation. Enjoy!</Say>
<Play>http://demo.twilio.com/docs/classic.mp3</Play>
</Response>
const fn = input => input.match(/(\w)\1+|\w{1}/gm).map(x => [x, x.length]);
const width = window.innerWidth;
const height = window.innerHeight;
const maxPoints = Math.floor((parseInt(width, 10) + parseInt(height, 10)) / 4);
document.getElementById("app").innerHTML = `
<canvas id="myCanvas" width="${width}px" height="${height}px" />
`;
var c = document.getElementById("myCanvas");
@JamieDixon
JamieDixon / sum.js
Last active September 16, 2020 15:42
function sum(...args) {
function inner(...innerArgs) {
return sum(...args, ...innerArgs);
}
inner.valueOf = () => args.reduce((x, y) => x + y);
return inner;
}
const hasAnyOwnProp = o => {
for(let p in o) {
return true;
}
return false
}
const a = hasAnyOwnProp({ bob: 'bob', sam: 'sam' });
const Empty = Symbol();
const stateIdentity = 0;
const adjusters = {
'(': 1,
')': -1
}
const getClosingParenPositionRec = (start, str) => {
const useAutosave = (saveFn, timeout, dependencies) => {
const isFirstLoad = useRef(true);
useEffect(() => {
if (isFirstLoad.current) {
isFirstLoad.current = false;
return;
}
const timer = setTimeout(saveFn, 1000);
const sortArrayByList = (fn, arr, order) =>
arr.sort(
(item1, item2) =>
order.indexOf(fn(item1)) > order.indexOf(fn(item2)) ? 1 : -1
);
const selector = x => x.name;
const arr = [{ name: 'Jamie' }, { name: 'Simon' }, { name: 'Paul' }, { name: 'Stuart' }];
const order = ['Stuart', 'Paul', 'Simon', 'Jamie'];
const useThrottle = (fn, wait) => {
const throttledRef = useRef(fn);
const lastCallRef = useRef({ fn: () => {}, args: null });
useEffect(
() => {
let isThrottling = false;
throttledRef.current = (...args) => {
if (isThrottling) {
lastCallRef.current = {