Skip to content

Instantly share code, notes, and snippets.

View aapzu's full-sized avatar

Aapeli Haanpuu aapzu

View GitHub Profile
const send = function(content) {
const waitFor = (condFunc, cb, timeout = 5) => new Promise((resolve) => {
const f = () => {
if (condFunc()) {
resolve()
} else {
setTimeout(f, timeout)
}
}
setTimeout(f, timeout)
@aapzu
aapzu / pick.test.ts
Created March 22, 2020 11:23
Type safe pick function
import pick, { pickAndGetRest } from "./pick"
describe("pick util", () => {
it("picks from an object", () => {
const obj = {
a: 1,
b: 2,
c: 3,
foo: "bar",
bar: "bah",
const NUMBERS = 1000000
const TESTS = 100
const startTime = Date.now()
console.log(`Testing calculating the sum of ${NUMBERS} numbers\n`)
const forLoops = []
const whileLoops = []
@aapzu
aapzu / useLocalStorage.ts
Created November 25, 2019 15:13
useLocalStorage.ts
import { useState } from "react"
// tslint:disable-next-line:no-any
export const useLocalStorage = <T extends any>(key: string, initialValue: T) => {
const [storedValue, setStoredValue] = useState<T>(() => {
try {
// Get from local storage by key
const item = window.localStorage.getItem(key)
// Parse stored json or if none return initialValue
return item ? JSON.parse(item) : initialValue
<html>
<heAD>
</HEAD>
<body>
<p>sdflkasdjföaslfkjasföl</p>
<script>
setInterval(() => {
document.querySelector('p').style.color = 'red'
}, 2000)
0xAf16EA680090E81af0ACf5e2664a19a37F5a3c43
0xAf16EA680090E81af0ACf5e2664a19a37F5a3c43