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
{ | |
"$schema": "https://vega.github.io/schema/vega-lite/v5.json", | |
"title": "Top 5 Medal Holders", | |
"description": "Data as of 2024-08-04 from https://www.kaggle.com/datasets/piterfm/paris-2024-olympic-summer-games?resource=download&select=medals_total.csv", | |
"config": { | |
"axisX": { | |
"labelAngle": 0 | |
} | |
}, | |
"data": { |
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
country_code | Gold Medal | Silver Medal | Bronze Medal | Total | |
---|---|---|---|---|---|
CHN | 16 | 12 | 9 | 37 | |
USA | 14 | 24 | 23 | 61 | |
FRA | 12 | 14 | 15 | 41 | |
AUS | 12 | 8 | 7 | 27 | |
GBR | 10 | 10 | 13 | 33 | |
KOR | 9 | 7 | 5 | 21 | |
JPN | 8 | 5 | 9 | 22 | |
ITA | 6 | 8 | 5 | 19 | |
NED | 6 | 4 | 4 | 14 |
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 fs = require('fs'); | |
const fetch = require('node-fetch'); | |
const cheerio = require('cheerio'); | |
main().catch(err => console.error(err)); | |
async function main() { | |
const SCARE_RE = /^((\d{1,2}):(\d{1,2})(?::(\d{1,2}))?).*– (.+)$/; | |
const $ = cheerio.load(fs.readFileSync('./notebooks/movielist.html', 'utf8')); | |
const $movieNames = $('td.column-1 > a'); |
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 syncScheduler: Scheduler = { | |
schedule(work) { | |
work(); | |
} | |
}; | |
const asyncScheduler: Scheduler = { | |
schedule(work) { | |
setTimeout(work, 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
interface Scheduler { | |
schedule(work: Function): void; | |
} |
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
outer | |
.pipe(concatMap(createInner)) | |
.subscribe(x => console.log("[concatMap] outer:", x), undefined, () => | |
console.log("[concatMap] done!") | |
); |
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 concatMap<T, R>( | |
project: (value: T, index: number) => Observable<R> | |
): OperatorFunction<T, R> { | |
let currentIndex = 0; | |
const buffer: Array<Observable<R>> = []; | |
const subscribeTo = ( | |
projected: Observable<R>, | |
obs: Observer<R>, | |
subscriptions: Set<Subscription> |
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 sleep(ms: number) { | |
return new Promise(resolve => setTimeout(resolve, ms)); | |
} | |
function createInner(x: number) { | |
return new Observable(obs => { | |
(async () => { | |
for (let i = 0; i < 3; i++) { | |
if (i > 0) await sleep(500); | |
obs.next(10 * x); |
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 mergeMap<T, R>( | |
project: (value: T, index: number) => Observable<R> | |
): OperatorFunction<T, R> { | |
let currentIndex = 0; | |
return source => | |
new Observable(obs => { | |
const subscriptions = new Set<Subscription>(); | |
const sub = source.subscribe( | |
x => { | |
const projected = project(x, currentIndex++); |
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 computeSquaredSum(): OperatorFunction<number, number> { | |
return source => | |
source.pipe( | |
map(n => n * n), | |
reduce((s, n) => s + n, 0), | |
); | |
} | |
oneThroughTen | |
.pipe(computeSquaredSum()) | |
.subscribe(x => console.log("Squared sum w/ custom op =", x)); |
NewerOlder