Skip to content

Instantly share code, notes, and snippets.

View furf's full-sized avatar
🎯
Focusing

Dave Furfero furf

🎯
Focusing
View GitHub Profile
const config: CodegenConfig = {
// @ts-ignore TypeScript describes this as a string, but it also supports a
// function.
schema: {
[CONTENTFUL_URI]: {
customFetch: initCustomFetch({
accessToken: CONTENTFUL_MANAGEMENT_ACCESS_TOKEN,
spaceId: CONTENTFUL_SPACE_ID,
environmentId: CONTENTFUL_ENVIRONMENT,
}),
<rmp-mock-video-controller>
<rmp-muted-toggle ?muted=${boolean('muted', true)}>
<rmp-mute-button id="story.mute" slot="mute-button">
<icon-mute fill></icon-mute>
</rmp-mute-button>
<rmp-unmute-button id="story.unmute" slot="unmute-button">
<icon-volume fill></icon-volume>
</rmp-unmute-button>
</rmp-muted-toggle>
</rmp-mock-video-controller>
export type Callback<T> = (value: T) => void;
export type Unsubscribe = () => void;
export default class Callbacks<T> {
private callbacks = new Set<Callback<T>>();
subscribe(callback: Callback<T>): Unsubscribe {
this.callbacks.add(callback);
return () => this.unsubscribe(callback);
}
@furf
furf / sleep.html
Created September 2, 2020 16:52
Detect system sleep and wake events in browser.
<html>
<head>
<title>sleep.js</title>
</head>
<body>
<h1>sleep.js</h1>
<script src="sleep.js"></script>
@furf
furf / setTimeoutWithThreshold.ts
Last active July 22, 2020 22:03
Experiments for canceling timeouts when system sleeps.
type Timestamp = number;
type Callback = (error: Error | null, timestamp: Timestamp) => void;
/**
* The default number of milliseconds beyond the expected time of execution to
* wait before assuming failure.
*/
const THRESHOLD = 10000;
/**
@furf
furf / timer.js
Last active July 9, 2020 16:20
A stopwatch-like timer
const Events = new Map();
function startEvent() {
return {
start: Date.now(),
end: null,
};
}
function endEvent(event) {
@furf
furf / index.js
Created July 13, 2019 15:59
Coding challenge for constructing and traversing (depth-first) trees.
// Found at https://www.glassdoor.com/Interview/Reddit-Senior-Software-Engineer-Interview-Questions-EI_IE796358.0,6_KO7,31.htm
// # a list of strings.Each string is a management / report relationship.
// #
// # EXAMPLE INPUT:
// #
// #[
// # 'B,E,F',
// # 'A,B,C,D',
// # 'D,G,I',
function reduceRot13Cipher(map, c, i, abc) {
const off = 13;
const len = abc.length;
const j = (i + off) % len;
map[c] = abc[j];
return map;
}
const rot13 = (() => {
const abc = 'abcdefghijklmnopqrstuvwxyz';
@furf
furf / 0.reverseList.js
Created August 14, 2018 16:32
Reverse a Linked List, because why not.
function buildList(values) {
return values.reduceRight((next, value) => ({ value, next }), null);
}
function getValues(node) {
const values = [];
while (node) {
values.push(node.value);
node = node.next;
}
@furf
furf / postmortem.md
Created June 22, 2018 02:31 — forked from mlafeldt/postmortem.md
Example Postmortem from SRE book, pp. 487-491

Shakespeare Sonnet++ Postmortem (incident #465)

Date

2015-10-21

Authors

  • jennifer
  • martym