This file contains 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 { getInitialState, syncLocalStorageWithRedux } from './util-localStorage' | |
const reduxStorageKey = 'my-application:' | |
const ONE_SECOND = 1000 | |
const ONE_MINUTE = ONE_SECOND * 60 | |
const ONE_HOUR = ONE_MINUTE * 60 | |
const ONE_DAY = ONE_HOUR * 24 | |
const ONE_YEAR = ONE_DAY * 365 | |
// create a white list. key is the redux store key, and lifeSpan is |
This file contains 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
#!/usr/bin/python | |
from urlparse import urlparse, parse_qs | |
from PIL import Image | |
import os | |
import json | |
print "Content-Type: application/json" | |
print "" |
This file contains 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 React, { useEffect, useRef, useState } from 'react' | |
import './LazyImage.scss' | |
const LazyImage = (props) => { | |
const [ isLoaded, setIsLoaded ] = useState(false) | |
const [ isVisible, setIsVisible ] = useState(false) | |
const { src, alt, width, height, className } = props | |
const placeHolderStyle = {paddingBottom: `${(height / width) * 100}%`} | |
const imageRef = useRef() |
This file contains 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 const pruneClosePoints = function (points, factor = .7) { | |
const culled = new Set() | |
const pointsWithD = points.map((point, i) => { | |
const nPoint = points[i + 1] || points[i] | |
const xDist = points[i][0] - nPoint[0] | |
const yDist = points[i][1] - nPoint[1] | |
return [...point, Math.hypot( xDist, yDist ), i] | |
}).sort((a, b) => b[2] - a[2]) |
This file contains 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 const getContrastColor = function (bgColor) { | |
var color = (bgColor.charAt(0) === '#') ? bgColor.substring(1, 7) : bgColor | |
var r = parseInt(color.substring(0, 2), 16) // hexToR | |
var g = parseInt(color.substring(2, 4), 16) // hexToG | |
var b = parseInt(color.substring(4, 6), 16) // hexToB | |
var uiColors = [r / 255, g / 255, b / 255] | |
var c = uiColors.map((col) => { | |
if (col <= 0.03928) { return col / 12.92 } | |
return Math.pow((col + 0.055) / 1.055, 2.4) |
This file contains 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 { useState, useCallback, useEffect } from 'react' | |
const customEvent = 'myMagicalStorageHook' | |
export default function useLocalStorage( | |
key, | |
initialValue, | |
lifeSpan = Infinity | |
) { | |
const [storedValue, setStoredValue] = useState(() => { |
This file contains 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 default function longPressEvents(callback, ms = 500) { | |
let timeout = null | |
const start = () => (timeout = setTimeout(callback, ms)) | |
const stop = () => timeout && window.clearTimeout(timeout) | |
return callback ? { | |
onMouseDown: start, | |
onMouseUp: stop, | |
onMouseLeave: stop, |
This file contains 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
const code = [ | |
'ArrowUp', 'ArrowUp', 'ArrowDown', | |
'ArrowDown', 'ArrowLeft', 'ArrowRight', | |
'ArrowLeft', 'ArrowRight', 'KeyB', 'KeyA' | |
]; | |
const useKonami = () => { | |
const [isActive, setActive] = useState(false); |
This file contains 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 { useState } from 'react'; | |
const useHistory = (initialState) => { | |
const [history, setHistory] = useState([initialState]); | |
const [historyPos, setHistoryPos] = useState(0); | |
const canUndo = historyPos; | |
const canRedo = historyPos !== history.length - 1; | |
const value = history[historyPos]; |