Skip to content

Instantly share code, notes, and snippets.

View glen-84's full-sized avatar

Glen glen-84

  • Cape Town, South Africa
View GitHub Profile
@glen-84
glen-84 / IRepository.cs
Created February 2, 2024 13:39
Generic repository interface
public interface IRepository<TAggregateRoot> where TAggregateRoot : IAggregateRoot
{
public void Add(params TAggregateRoot[] entities);
public void Remove(params TAggregateRoot[] entities);
public Task<TAggregateRoot?> SingleOrDefaultAsync(
ISpecification<TAggregateRoot> specification,
CancellationToken cancellationToken = default);
@glen-84
glen-84 / AddTemporaryFileInputValidator.cs
Created February 2, 2024 13:14
HC validation example
public sealed class AddTemporaryFileInputValidator : AbstractValidator<AddTemporaryFileInput>
{
public AddTemporaryFileInputValidator()
{
this.RuleFor(f => f.TemporaryFileName)
.NotEmptyWithLength(FileName.MinimumLength, FileName.MaximumLength) // using VO metadata
.Must(FileName.ValidateCharacters) // using VO validation logic
.WithErrorCode(nameof(FileName.Errors.FileNameDisallowedCharacters)); // using VO validation message/code
}
}
@glen-84
glen-84 / hc-custom-filter.cs
Created May 15, 2023 14:32
HC custom filter WIP
public class EntityIdOperationFilterInputType : FilterInputType
{
protected override void Configure(IFilterInputTypeDescriptor descriptor)
{
descriptor
.Operation(DefaultFilterOperations.Equals)
.Type<LongType>();
}
}
@glen-84
glen-84 / index.ts
Created April 20, 2021 09:53
Koa middleware for Rendertron.
import axios from "axios";
import type {IncomingMessage} from "node:http";
import type {Middleware} from "koa";
/**
* A default set of user agent patterns for bots/crawlers that do not perform
* well with pages that require JavaScript.
*/
export const botUserAgents = [
// spell-checker:disable
@glen-84
glen-84 / gg-number-array.ts
Created February 13, 2019 10:59
Number array custom attribute
import {autoinject, bindingMode, customAttribute} from "aurelia-framework";
/**
* Ensures that array elements are numbers.
*
* TODO: Using this custom attribute because value converters and binding behaviors are not working well with
* multi-select elements. See https://github.com/aurelia/binding/issues/611.
*/
@autoinject
@customAttribute("gg-number-array", bindingMode.twoWay)
@glen-84
glen-84 / app.html
Last active August 21, 2017 17:25 — forked from jdanyow/app.html
Aurelia set select options and value
<template>
<h1>Instructions</h1>
<ol>
<li>Click the "Set value" button (selected option changes correctly)</li>
<li>Increment number to 3</li>
<li>Click the "Set options and value" button (selected option is not set correctly)</li>
</ol>
<select value.bind="matchGame.winner.id">
@glen-84
glen-84 / app.html
Created March 5, 2017 15:52 — forked from plwalters/app.html
DI inheritance
<template>
<h1>Dialog Repro</h1>
<button click.delegate="submit()">Open Dialog</button>
</template>
<template>
<require from="./select2-custom-attribute"></require>
<require from="./debug"></require>
<h1>Standard Select</h1>
<select value.bind="selectedThings" style="width: 100%">
<option repeat.for="thing of things" model.bind="thing">${thing.name}</option>
</select>
<h1>Select2</h1>
@glen-84
glen-84 / letter-to-dc.txt
Last active May 21, 2016 16:23
Letter to DC
Hi,
I'm noticing that a disturbing number of package managers[1] and other software projects[2] are making use of JSON as a
configuration format, which is starting to bother me (probably more than it should), since JSON is a data serialization
format, and was not intended for this purpose (as I understand it).
Have you considered writing a new specification for a format that is more suited to such uses? Something similar to
JSON5 or YAML. YAML is pretty cool, but people don't like/use it because (I assume):
1. It has a stupid name.
// Note: The definitions below are incomplete, they are just used to satisfy the TypeScript compiler for now.
declare module "glob2base" {
var glob2base: any;
export = glob2base;
}
declare module "gulp" {
var gulp: any;
export = gulp;