Skip to content

Instantly share code, notes, and snippets.

View mkulke's full-sized avatar

Magnus Kulke mkulke

View GitHub Profile
@mkulke
mkulke / setup.sql
Last active July 13, 2016 22:33
node pg tuple query
CREATE TABLE test (
id integer,
col_a text,
col_b text,
PRIMARY KEY(id)
);
INSERT INTO test VALUES (0, 'abc', 'def');
INSERT INTO test VALUES (1, 'abc', 'ghi');
INSERT INTO test VALUES (2, 'jkl', 'ghi');
Fetching metadata from s3://transit-hub-gtfs/normalized/Oceania/Australia/AirlieBeach-TransLinkBrisbane.zip...done
MD5 mismatch w/ import history in db, downloading bundle...done
Importing airliebeach-translinkbrisbane data...done (1s)
NOTICE: no non-null/empty features, unable to compute statistics
NOTICE: no non-null/empty features, unable to compute statistics
Fetching metadata from s3://transit-hub-gtfs/normalized/North-America/United-States-of-America/New-York/Albany-CDTA.zip...done
MD5 mismatch w/ import history in db, downloading bundle...done
Importing albany-cdta data...done (21s)
Fetching metadata from s3://transit-hub-gtfs/normalized/North-America/United-States-of-America/Texas/Austin-Capmetro.zip...done
MD5 mismatch w/ import history in db, downloading bundle...done
@mkulke
mkulke / cache.js
Last active April 17, 2017 18:00
RxJS cache
const Rx = require('rxjs/Rx');
const PERFORM = 1;
const INVALIDATE_CACHE = 2;
function asyncOp() {
return Promise.resolve(Date().toString());
}
const clearCacheInterval$ = Rx.Observable.interval(5000);
@mkulke
mkulke / rx_omit_duplicates.ts
Last active October 13, 2017 22:14
rx_omit_duplicates.ts
import Rx = require('rxjs/Rx');
interface Obj {
id: number;
}
type Chunk = Obj[]
const chunks$: Rx.Observable<Chunk> = Rx.Observable.from([
[ { id: 1 }, { id: 2} ],
@mkulke
mkulke / rx_tx_handing.ts
Last active October 13, 2017 22:14
rx_tx_handling.ts
import Rx = require('rxjs/Rx');
interface Obj {
id: number;
}
type Chunk = Obj[]
const chunks$: Rx.Observable<Chunk> = Rx.Observable.from([
[ { id: 1 }, { id: 2} ],
@mkulke
mkulke / contravariance.ts
Created January 9, 2018 16:46
contravariant fn argument types
interface Vehicle {
color: string;
}
interface Car extends Vehicle {
drive: () => void;
}
interface Bike extends Vehicle {
peddle: () => void;
@mkulke
mkulke / partition.ts
Last active April 28, 2018 14:10
lackluster partition with conditional types
type Pred<T, U extends T> = (v: T) => v is U;
function filter<T, U extends T>(coll: T[], pred: Pred<T, U>): U[] {
const seed: U[] = [];
return coll.reduce((acc: U[], val: T) => {
if (pred(val)) {
return [...acc, val];
}
return acc;
}, seed);
type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
function without<T extends object, K extends keyof T>(
obj: T,
key: K,
): Omit<T, K> {
const newObj = Object.assign({}, obj);
delete newObj[key];
return newObj;
}
@mkulke
mkulke / rxjs-operators.ts
Created May 8, 2018 13:37
RxJS operators
import { Observable } from 'rxjs/Rx';
type Tuple<T, U> = [T, U];
/**
* Operator which for values of a promise to be concated to an emission of the observable. For each
* emission, the result of the promise will be triggered and appended into an array with the
* emitted value, which can be used in the next emission block. Returns a lambda that can be used
* within `let`, for example.
*
@mkulke
mkulke / future_example.ts
Last active March 3, 2019 16:21
future example using ts-monads
import * as future from './future';
import * as result from './result';
import { get } from 'https';
interface Tuple {
name: string;
len: number;
}
function printTuple(tuple: Tuple): void {