A Pen by Christian Juth on CodePen.
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
clearStorage = function(exceptions){ | |
var storage = localStorage | |
var keys = []; | |
var exceptions = [].concat(exceptions) //prevent undefined | |
//get storage keys | |
$.each(localStorage, function(key, val) { | |
keys.push(key); | |
}); |
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
function openPopup(url: string, height: number, width: number) { | |
if (typeof window !== "undefined") { | |
const newwindow = window.open( | |
url, | |
"Share Window", | |
`height=${height}, width=${width}, top=` + | |
(window.innerHeight / 2 - height) + | |
", left=" + | |
(window.innerWidth / 2 - width) + | |
", toolbar=0, location=0, menubar=0, directories=0, scrollbars=0" |
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
function useMouseSpeed(updateInterval = 500) { | |
const lastUpdateRef = useRef(Date.now()) | |
const prevPositionRef = useRef<MousePosition | null> (null) | |
const currentPositionRef = useRef<MousePosition | null> (null) | |
const [speed, setSpeed] = useState(0) | |
useEffect(() => { | |
function trackMouse({ pageX: x, pageY: y }: MouseEvent) { | |
x = x / window.innerWidth | |
y = y / window.innerHeight |
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 { createMachine, useStateMachine } from "./stateMachine"; | |
const machine = createMachine({ | |
initial: "saved", | |
context: { | |
input: "" | |
}, | |
states: { | |
saved: { | |
edit: "hasChanges" |
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
function memo(fn) { | |
const dict = {} | |
let id | |
const perform = { calls: 0, memoHits: 0 } | |
return (...args) => { | |
perform.calls++ | |
clearTimeout(id) | |
id = setTimeout(() => { | |
console.log(`memo hit rate = ${perform.memoHits}/${perform.calls}`) | |
}, 1000) |
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
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions |
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
def sort(arr): | |
length = len(arr) | |
if length >= 2: | |
splitIndex = int(length / 2) | |
left = arr[0:splitIndex] | |
right = arr[splitIndex:length] | |
left = sort(left) |
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
<html> | |
<head> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<link href="https://fonts.googleapis.com/css?family=Open+Sans|Roboto:900|Pacifico" rel="stylesheet"> | |
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"> | |
<link rel='stylesheet' href='style.css'/> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> | |
<script src='script.js'></script> | |
</head> | |
<body> |
A Pen by Christian Juth on CodePen.
NewerOlder