Skip to content

Instantly share code, notes, and snippets.

# TYPE worker_pool_queue_size gauge
worker_pool_queue_size{pool_name="vert.x-internal-blocking",pool_type="worker"} 0.0
worker_pool_queue_size{pool_name="vert.x-worker-thread",pool_type="worker"} 0.0
# TYPE worker_pool_active gauge
worker_pool_active{pool_name="vert.x-internal-blocking",pool_type="worker"} 0.0
worker_pool_active{pool_name="vert.x-worker-thread",pool_type="worker"} 1.0
# TYPE jvm_gc_live_data_size_bytes gauge
jvm_gc_live_data_size_bytes 0.0
# TYPE jvm_buffer_count_buffers gauge
jvm_buffer_count_buffers{id="mapped - 'non-volatile memory'"} 0.0
type None = false
const none = false
type Equality<A> = (left: A, right: A) => boolean
function areSameReference<A>(left: A, right: A): boolean {
return left === right
}
@wernerdegroot
wernerdegroot / aside_zoom.ts
Created June 12, 2019 19:30
Blog "Leibniz equality in TypeScript", aside `zoom`
function zoom(dayStart: number, dayEnd: number, zoomFactor: number): [number, number] {
// What is the middle of the time range?
// When zooming in or out, the middle of the time range should stay the middle.
const dayMiddle = (dayEnd + dayStart) / 2
// Determine what the new time range should be using the `zoomFactor`.
const oldTimeRange = dayEnd - dayStart
const newTimeRange = oldTimeRange * zoomFactor
// Calculate the new boundaries of the time range:
@wernerdegroot
wernerdegroot / graphprops.ts
Created June 12, 2019 19:22
Blog "Leibniz equality in TypeScript"
type GraphProps = {
activities: Activity[]
dayStart: number
dayEnd: number
onZoomIn: () => void
onZoomOut: () => void
}
@wernerdegroot
wernerdegroot / exhaustMapWithLatest.test.ts
Last active June 18, 2019 09:53
New RxJs operator `exhaustMapWithLatest`
import { TestScheduler } from 'rxjs/testing'
import { exhaustMapWithLatest } from './exhaustMapWithLatest'
import { of } from 'rxjs'
describe('exhaustMapWithLatest', () => {
it('should act as `map` when the inner `Observable<..>` completes directly', () => {
const scheduler = new TestScheduler((actual, expected) => {
expect(actual).toEqual(expected)
})
enum HListType {
HCons,
HNil
}
type HNil = { type: typeof HListType.HNil }
type HCons<Head, Tail extends HList<any, any>> = {
type: typeof HListType.HCons
head: Head
tail: Tail
}
@wernerdegroot
wernerdegroot / querybeak.ts
Last active February 22, 2019 18:08
QueryBeak
type Condition<O> = (o: O) => boolean
type QueryableProperty<Alias extends string, Subject, Property> = {
eq(other: Property): Condition<{ [K in Alias]: Subject }>
eq<OtherAlias extends string, OtherSubject>(other: QueryableProperty<OtherAlias, OtherSubject, Property>): Condition<{ [K in Alias]: Subject } & { [K in OtherAlias]: OtherSubject }>
}
type Queryable<Alias extends string, Subject> = { [KS in keyof Subject]: QueryableProperty<Alias, Subject, Subject[KS]> }
type Query<O> = {
where(condition: Condition<O>): Query<O>
@wernerdegroot
wernerdegroot / Experiments.ts
Last active January 20, 2019 16:00
Experiments with capturing a generic continuation as a Promise
type Hkts<A> = {
Id: A
Array: A[]
}
type HktToken = keyof Hkts<any>
type Continuation<T extends HktToken, A> = <B>(c: (a: A) => Hkts<B>[T]) => Hkts<B>[T]
type FlatMap<T extends HktToken> = <A, B>(fa: Hkts<A>[T], fn: (a: A) => Hkts<B>[T]) => Hkts<B>[T]
@wernerdegroot
wernerdegroot / Lens.ts
Last active November 9, 2018 19:55
Lens.ts
class Lens<Outer, Inner> {
static create<O>(): Lens<O, O> {
return new Lens(o => o, o => o, [])
}
constructor(public readonly read: (outer: Outer) => Inner, public readonly write: (inner: Inner, outer: Outer) => Outer, public readonly path: Array<string | number | Symbol>) { }
property<K extends keyof Inner>(k: K): Lens<Outer, Inner[K]> {
return new Lens(
@wernerdegroot
wernerdegroot / Lazy.ts
Created October 18, 2018 09:42
Lazy.ts
type Lazy<A> = () => A
const Lazy = {
map<A, B>(l: Lazy<A>, fn: (a: A) => B): Lazy<B> {
return lazy(() => fn(l()))
}
}
function lazy<A>(fn: () => A): Lazy<A> {
let memoized: { value: A } | false = false