Skip to content

Instantly share code, notes, and snippets.

View RomkeVdMeulen's full-sized avatar

Romke van der Meulen RomkeVdMeulen

View GitHub Profile
{
"openapi": "3.0.2",
"info": {
"title": "Ferry - waterfront-backend",
"version": "1.0.0"
},
"servers": [
{
"url": "https:\/\/waterfront.sandwaveio.dev"
}
@RomkeVdMeulen
RomkeVdMeulen / aurelia_vm_class_naming_convention.ts
Created December 9, 2019 17:44
Override the naming convention for View Model class names in Aurelia
import {HtmlBehaviorResource} from "aurelia-framework";
const orig: (...args: any[]) => any = HtmlBehaviorResource.convention;
HtmlBehaviorResource.convention = function(name: string, ...args: any[]) {
if (name.endsWith("Component")) {
name = name.replace(/Component$/, "CustomElement");
}
if (name.endsWith("Route")) {
name = name.replace(/Route$/, "CustomElement");
}
@RomkeVdMeulen
RomkeVdMeulen / request-context.ts
Created August 2, 2019 08:32
Context wrapper for async (request) operations with some useful state flags
/**
* Vormt een wrapper om async operaties waarin de staat van de operatie
* bijgehouden wordt.
*/
export class AsyncContext {
bezig = false;
mislukt = false;
geslaagd = false;
@RomkeVdMeulen
RomkeVdMeulen / advanced-object-types.ts
Created August 2, 2019 08:29
Some advanced partial object type definitions for TypeScript
// tslint:disable:align ban-types
export type DeepPartial<T> =
T extends Array<infer U> ? DeepPartialArray<U> :
T extends ReadonlyArray<infer V> ? DeepPartialReadonlyArray<V> :
T extends object ? DeepPartialObject<T> :
T;
export type DeepPartialNoMethods<T> =
T extends Array<infer U> ? DeepPartialArrayNoMethods<U> :
T extends ReadonlyArray<infer V> ? DeepPartialReadonlyArrayNoMethods<V> :
@RomkeVdMeulen
RomkeVdMeulen / confirm-unload.ts
Last active August 27, 2019 14:59
Decorator for Aurelia routes that ask the user to confirm when unloading with unsaved changes
import {decorateMethod} from "util/objects";
export interface ConfirmUnloadConfig {
hasUnsavedChanges(): boolean;
getUnloadConfirmMessage(): string;
}
export function confirmUnload(viewModel: any): any {
decorateMethod(viewModel, "attached", function attached() {
const self: ConfirmUnloadConfig = this;
@RomkeVdMeulen
RomkeVdMeulen / app.html
Last active August 1, 2019 10:29 — forked from jsobell/app.html
Aurelia Child Router with Parameters
<template>
<router-view></router-view>
</template>
@RomkeVdMeulen
RomkeVdMeulen / 0_src-numbered-textarea.html
Last active August 17, 2018 13:42
An Aurelia component showing a textarea with line-numbers and locked height
<template>
<div class="element-wrapper ${invoerFocus ? 'focus' : ''} ${invoerRegels.length >= 10 ? 'vol' : ''}"
e2e="wrapper" data-focus.bind="invoerFocus">
<ol class="regelnummers" ref="regelnummers" e2e="regelnummer-wrapper" css="height: ${hoogte + 24}px">
<li repeat.for="i of aantalGetoondeRegels" e2e="regelnummer"
data-actief.bind="invoerRegels.length > i && invoerRegels[i].trim() !== ''"
class="regelnummer ${invoerRegels.length > i && invoerRegels[i].trim() !== '' ? 'actief' : ''}"></li>
</ol>
<div class="invoer-wrapper">
<textarea value.bind="invoer" ref="invoerElement" e2e="invoer"
@RomkeVdMeulen
RomkeVdMeulen / analytics.ts
Created February 22, 2018 16:27
Aurelia Custom Attribute for registering events with Google Universal Analytics
import {autoinject, bindable} from "aurelia-framework";
declare const ga: (
command: "send",
type: "event",
category?: string,
action?: string,
label?: string,
) => void;
interface OperationQueue {
queue: Promise<void>;
}
export function makeOperationQueue(): OperationQueue {
return {queue: Promise.resolve()};
}
export function queuedOperation(operationQueue: OperationQueue) {
return function(_target: any, _key: string, descriptor: TypedPropertyDescriptor<(...args: any[]) => any>) {