Skip to content

Instantly share code, notes, and snippets.

View mkulke's full-sized avatar

Magnus Kulke mkulke

View GitHub Profile
#!/bin/bash
docker run -v $PWD/bla:/data mediagis/osmtools osmconvert /data/berlin.pbf -b=10.5,49,11.5,50 -o=/data/cropped.pbf
xsv input -d ";" < adressen-be.txt | xsv search --no-headers -s 15 '10437' | xsv select 14,10,11 > addr.csv
/pelias-pbf2json -leveldb=bla/ -tags="addr:housenumber+addr:street+addr:postcode~10437" berlin.pbf | jq -s -r '.[] | [.tags."addr:housenumber", .tags."addr:street"] | @csv' > addr.csv
sort -k1,1 -k2,2n -t ',' addr.csv
@mkulke
mkulke / limit.ts
Created June 25, 2019 22:15
limit concurrency of promises
async function limitConcurrency<T, U>(
arr: T[],
fn: (t: T) => Promise<U>,
limit: number,
): Promise<U[]> {
const results: Promise<U>[] = [];
const pool: Promise<void>[] = [];
for (const elem of arr) {
// add promise to the pool
@mkulke
mkulke / yaml.go
Created April 16, 2019 04:56
go lang yaml unmarshaling
package main
import (
"fmt"
"log"
"gopkg.in/yaml.v2"
)
type Environment struct {
@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 {
@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.
*
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 / 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);
@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 / 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 / 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} ],