Skip to content

Instantly share code, notes, and snippets.

View traviskaufman's full-sized avatar

Travis Kaufman traviskaufman

View GitHub Profile
@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-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-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));
@traviskaufman
traviskaufman / 02-03-demystifying-rxjs-sqsum-test-1.ts
Created October 25, 2019 14:03
Demystifying RxJS, Part II: Sum of Squares with pipe() / operators
const oneThroughTen = of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
oneThroughTen
.pipe(
map(n => n * n),
reduce((s, n) => s + n, 0)
)
.subscribe(sqSum => console.log("Squared sum =", sqSum));
@traviskaufman
traviskaufman / 05-demystifying-rxjs-fromEvent.ts
Created October 18, 2019 18:52
Demystifying RxJS, Part I: fromEvent()
function fromEvent<T extends Event = Event>(
target: EventTarget,
eventName: string
): Observable<T> {
return new Observable(obs => {
const listener: EventListener = (evt: T) => {
obs.next(evt);
};
target.addEventListener(eventName, listener);
return () => target.removeEventListener(eventName, listener);
@traviskaufman
traviskaufman / 03-demystifying-rxjs-of.ts
Created October 18, 2019 18:33
Demystifying RxJS, Part I: of()
function of<T>(...values: T[]): Observable<T> {
return new Observable(obs => {
for (const value of values) {
obs.next(value);
}
obs.complete();
});
}
// Logs:
@traviskaufman
traviskaufman / 02-demystifying-rxjs-observable-test.ts
Created October 18, 2019 18:00
Demystifying RxJS, Part I: Basic Observable Test
const observable = new Observable(subscriber => {
subscriber.next(1);
subscriber.next(2);
subscriber.next(3);
setTimeout(() => {
subscriber.next(4);
subscriber.complete();
}, 1000);
});
@traviskaufman
traviskaufman / 01-demystifying-rxjs-observable.ts
Last active October 18, 2019 17:56
Demystifying RxJS Part I: Observable Implementation
interface Observer<T> {
next(value: T): void;
error(err: any): void;
complete(): void;
}
interface Subscription {
unsubscribe(): void;
}
# ipython-utils/researchenv/magics.py
from IPython.core.magic import Magics, magics_class, cell_magic, needs_local_scope
from IPython.core.magic_arguments import magic_arguments, argument, parse_argstring
from IPython.core.interactiveshell import InteractiveShell
from IPython.core.display import display
from google.cloud import bigquery
@magics_class
class ResearchEnvMagics(Magics):
# ipython-utils/researchenv/__init__.py
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from IPython.core.interactiveshell import InteractiveShell
def load_ipython_extension(ipython: InteractiveShell):
print('%matplotlib inline')