Skip to content

Instantly share code, notes, and snippets.

View lusbuab's full-sized avatar

Florian Hämmerle lusbuab

View GitHub Profile
@lusbuab
lusbuab / refresh-after.js
Created December 2, 2019 21:17
Refresh the page if it was inactive for too long.
;(function(refreshAfter){
var hideTime = null
document.addEventListener("visibilitychange", function() {
if (document.hidden) {
hideTime = Date.now()
} else if (hideTime && Date.now() - hideTime > refreshAfter) {
location.reload()
}
}, false)
}(5000))
@lusbuab
lusbuab / person.ts
Last active December 4, 2018 13:01
import { Record } from 'immutable'
interface PersonProps {
firstName: string
lastName: string
}
const defaultPersonProps: PersonProps = {
firstName: '',
lastName: '',
@lusbuab
lusbuab / sha-1.js
Last active April 11, 2023 05:44
Calculating SHA-1 in the Browser
async function sha1(str) {
const enc = new TextEncoder();
const hash = await crypto.subtle.digest('SHA-1', enc.encode(str));
return Array.from(new Uint8Array(hash))
.map(v => v.toString(16).padStart(2, '0'))
.join('');
}
// await sha1('hello, world!');
// outputs: 1f9d3c707d53f3d16c53dd73d70a6ce7596a9