Skip to content

Instantly share code, notes, and snippets.

View traviskaufman's full-sized avatar

Travis Kaufman traviskaufman

View GitHub Profile
@traviskaufman
traviskaufman / spec.json
Created August 4, 2024 16:56
Top 5 Olympic Medal Holders using Kaggle Dataset
{
"$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": {
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
@traviskaufman
traviskaufman / scrape-timestamps.js
Created October 31, 2019 01:50
Timestamp scraping script used for r/dataisbeautiful October 2019 Challenge
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');
@traviskaufman
traviskaufman / 03-02-demystifying-rxjs-schedulers.ts
Created October 28, 2019 21:40
Demystifying RxJS, Part III: Concrete Schedulers
const syncScheduler: Scheduler = {
schedule(work) {
work();
}
};
const asyncScheduler: Scheduler = {
schedule(work) {
setTimeout(work, 0);
}
@traviskaufman
traviskaufman / 03-01-demystifying-rxjs-scheduler-interface.ts
Created October 28, 2019 21:37
Demystifying RxJS, Part III: Scheduler Interface
interface Scheduler {
schedule(work: Function): void;
}
@traviskaufman
traviskaufman / 02-08-demystifying-rxjs-concatMap-test.ts
Created October 25, 2019 22:40
Demystifying RxJS, Part II: concatMap test
outer
.pipe(concatMap(createInner))
.subscribe(x => console.log("[concatMap] outer:", x), undefined, () =>
console.log("[concatMap] done!")
);
@traviskaufman
traviskaufman / 02-07-demystifying-rxjs-concatMap.ts
Last active November 27, 2019 22:26
Demystifying RxJS, Part II: concatMap
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>
@traviskaufman
traviskaufman / 02-06-demystifying-rxjs-mergemap-test.ts
Last active October 25, 2019 19:44
Demystifying RxJS, Part II: MergeMap test
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);
@traviskaufman
traviskaufman / 02-05-demystifying-rxjs-mergemap.ts
Last active November 26, 2019 17:31
Demystifying RxJS, Part II: MergeMap
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++);
@traviskaufman
traviskaufman / 02-04-demystifying-rxjs-custom-op.ts
Created October 25, 2019 18:49
Demystifying RxJS, Part II: Custom operators
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));