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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Sticky scroll spy example</title> | |
<style> | |
html { | |
scroll-behavior: smooth; |
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 ALPHABET = "RKYM5C4H07P9EGWJ1BZQ8V3S62FXNTDA" | |
const BASE_LENGTH = ALPHABET.length | |
const SHORT_CODE_LENGTH = 6 | |
function toBase (input) { | |
let number = input | |
if (number === 0) { | |
return ALPHABET[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
#!/usr/bin/env node | |
const readline = require("readline"); | |
const lines = []; | |
function sortBooks(a, b) { | |
if (a.score > b.score) return 1; | |
if (a.score < b.score) return -1; | |
return 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
#!/usr/bin/env node | |
require("lodash.combinations"); | |
const { flatMap, combinations } = require("lodash"); | |
const readline = require("readline"); | |
const lines = []; | |
function processInput(lines) { | |
const [firstLine, lastLine] = lines; |
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 * generateMultiplesOf (number) { | |
for (let factor = 2;; factor++) { | |
yield number * factor | |
} | |
} | |
function * generatePrimes (maxNumber = 1000) { | |
const firstPrime = 2 | |
const nonPrimeNumbers = new Set() |
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 takePhoto = () => new Promise((resolve) => (setTimeout(resolve, Math.random() * 1E3 + 5E2, 'photo'))) | |
const makeCountdown = (seconds) => | |
Rx.Observable | |
.concat( | |
Rx.Observable | |
.interval(1E3) | |
.take(seconds), | |
Rx.Observable.defer(() => takePhoto()) | |
) |
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 simulateTask = () => new Promise((resolve) => (setTimeout(resolve, Math.random() * 1E3 + 500))) | |
const click$ = Rx.Observable | |
.fromEvent(document, 'click') | |
.scan((clickCount) => clickCount + 1, 0) | |
click$.switchMap( | |
() => Rx.Observable.fromPromise(simulateTask()), | |
(clickCount) => clickCount | |
) |
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
class App extends PureComponent { | |
constructor (props) { | |
super(props) | |
this.state = { | |
term: props.term, | |
items: [], | |
errorMessage: null | |
} |
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 createIdleTimer (delay = 5E3) { | |
const IDLE_POLL_TIMEOUT = 1E2 | |
const events = ['mousemove', 'mousedown', 'keydown', 'touchstart', 'scroll'] | |
return new Promise((resolve) => { | |
let idle = true | |
let timeout = null | |
let lastTimestamp = null | |
let elapsedTimeInMillis = 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 sliceBy(str, [ chunkSize = -1, ...rest ] = []) { | |
// Guard against infinite recursion | |
if (chunkSize < 1) { | |
return [str] | |
} | |
if (str.length <= chunkSize) { | |
return [str] | |
} | |
NewerOlder