Skip to content

Instantly share code, notes, and snippets.

View DanteDeRuwe's full-sized avatar

Dante De Ruwe DanteDeRuwe

View GitHub Profile
@DanteDeRuwe
DanteDeRuwe / enable-logging-in-karma-conf.js
Last active April 28, 2022 14:11
Enable logging in karma.conf.js
browserConsoleLogOptions: {
level: 'log',
format: '%b %T: %m',
terminal: true,
},
@DanteDeRuwe
DanteDeRuwe / lazy.directive.ts
Created June 16, 2022 12:32
Angular automatic lazy loading directive (using loading="lazy" if supported)
import { AfterViewInit, Directive, ElementRef } from '@angular/core';
@Directive({
selector: 'img',
})
export class LazyDirective extends Directive implements AfterViewInit {
constructor(private elementRef: ElementRef<HTMLImageElement>) {
super();
}
@DanteDeRuwe
DanteDeRuwe / video-speed.user.js
Created April 4, 2023 11:20
Video speed user script.
// ==UserScript==
// @name Video speed
// @author Dante De Ruwe
// @version 0.0.7
// @description Let's you change the speed for all HTML5 videos with the use of the square bracket keys.
// @namespace http://tampermonkey.net/
// @include *
// ==/UserScript==
(function () {
@DanteDeRuwe
DanteDeRuwe / cypress-run-local-parallel.sh
Last active January 30, 2024 08:06
Run cypress tests in parallel locally
########################################################################
# RUNS ALL .cy.ts FILES IN THE cypress/e2e FOLDER IN PARALLEL
# ARGUMENT $1: The path to the directory containing the cypress folder
########################################################################
baseCommand="npm run dev --" # change this if needed
echo ""
# validate argument
@DanteDeRuwe
DanteDeRuwe / ConfigureSwaggerGenOptions.cs
Last active June 13, 2024 14:44
Swagger extensions for minimal apis
using Asp.Versioning.ApiExplorer;
using Microsoft.Extensions.Options;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;
namespace BFF.API.Extensions.OpenApi;
public class ConfigureSwaggerGenOptions(IApiVersionDescriptionProvider versionProvider) : IConfigureNamedOptions<SwaggerGenOptions>
{
public void Configure(string? name, SwaggerGenOptions options) => Configure(options);
@DanteDeRuwe
DanteDeRuwe / RefitToResultMapper.cs
Created June 14, 2024 07:25
Map refit ApiResponse to an AspNetCore IResult
public static class ResultMapper
{
/// <summary>
/// A mapper to map to an IResult with potential content
/// </summary>
public static IResult MapToResult<TContent>(this IApiResponse<TContent> response)
{
return response.StatusCode switch
{
HttpStatusCode.OK when response.Content is not null => TypedResults.Ok(response.Content),