Skip to content

Instantly share code, notes, and snippets.

View jeroenheijmans's full-sized avatar

Jeroen Heijmans jeroenheijmans

View GitHub Profile
@jeroenheijmans
jeroenheijmans / example.js
Created August 23, 2020 11:11
OAuth2 Resource Owner Password Flow with vanilla JavaScript
// Please avoid "password" flow at all cost, it has been officially deprecated
// https://tools.ietf.org/html/draft-ietf-oauth-security-topics-15#section-2.4
// But, if you must use it, here's a simple way to do so:
async function getTokenResponse(clientId, identityServerUrl, username, password) {
const response = await fetch(identityServerUrl + "/connect/token", {
method: "POST",
headers: {
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
},
@jeroenheijmans
jeroenheijmans / localhost-ssl.conf
Created May 31, 2020 22:31
Certificate configuration for dotnet Ubuntu 20.04 localhost https dev
# Based on https://stackoverflow.com/a/59702094/419956 by user @chrisvdb cc-by-sa rev 2020.5.28.36925
# Not currently working for me on Ubuntu 20.04 though!
[req]
default_bits = 2048
default_keyfile = localhost.key
distinguished_name = req_distinguished_name
req_extensions = req_ext
x509_extensions = v3_ca
@jeroenheijmans
jeroenheijmans / destroyable.component.spec.ts
Created February 16, 2020 14:00
Destroyable Angular component
import { Subject } from 'rxjs';
import { Destroyable } from './destroyable.component';
class TestableDestroyable extends Destroyable { }
describe('Destroyable', () => {
it('should construct with observable', () => {
const component = new TestableDestroyable();
expect(component.destroyed$ instanceof Subject).toBeTruthy();
});
@jeroenheijmans
jeroenheijmans / Foo.Tests.csproj
Created August 19, 2019 12:01
FluentValidation auto-registration with string validators repro
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.7" />
@jeroenheijmans
jeroenheijmans / choco-install.ps1
Last active November 16, 2018 10:23
Chocolatey Install DevTools
choco install adobereader -y
choco install googlechrome -y
choco install firefox -y
choco install 7zip -y
choco install notepadplusplus -y
choco install git -y
choco install putty -y
choco install nodejs -y
choco install skype -y
choco install sysinternals -y
@jeroenheijmans
jeroenheijmans / angular-oauth2-oidc-extra-logging-snippet.ts
Last active May 20, 2019 12:15
Custom logging for angular-oauth2-oidc library
import { OAuthErrorEvent } from 'angular-oauth2-oidc';
// ...
this.authService.events.subscribe(event => {
if (event instanceof OAuthErrorEvent) {
console.error(event);
} else {
console.warn(event);
}
@jeroenheijmans
jeroenheijmans / decorated-oauth-storage.ts
Created June 13, 2018 11:18
OAuthStorage wrapper for debugging angular-oauth2-oidc library
// Usage:
// { provide: OAuthStorage, useValue: decoratedStorage },
const decoratedStorage: OAuthStorage = {
getItem(key) {
const data = localStorage.getItem(key);
console.warn('get', key, data ? data.substring(0, 25) : data);
return data;
},
setItem(key, data) {
@jeroenheijmans
jeroenheijmans / ngb-momentjs-adapter.ts
Last active March 3, 2022 13:34
NgbDateAdapter for Moment.js values
import { NgbDateAdapter, NgbDateStruct } from '@ng-bootstrap/ng-bootstrap';
import { Injectable } from '@angular/core';
import * as moment from 'moment';
// Might need to polyfill depending on needed browser support...
const isInt = Number.isInteger;
@Injectable()
export class NgbMomentjsAdapter extends NgbDateAdapter<moment.Moment> {
@jeroenheijmans
jeroenheijmans / NgbDateStringParserFormatter.ts
Last active June 5, 2018 18:19
Parser/formatter for ngbDatepicker with dd-MM-yyyy format
// Formatter using "dd-MM-yyyy" string format:
// See: https://ng-bootstrap.github.io/#/components/datepicker/api#NgbDateParserFormatter
//
export class NgbDateStringParserFormatter extends NgbDateParserFormatter {
parse(value: string): NgbDateStruct {
if (!value) { return null; }
const parts = value.trim().split('-');
return {
@jeroenheijmans
jeroenheijmans / CsharpBuddy.cs
Last active April 16, 2018 07:35
CsharpBuddy
/* DISCLAIMER:
* This code is pure adhoc magic. NO WARRANTY or guarantees or
* whatsoever! Use at your own risk!!
*/
using System;
using System.Collections.Generic;
using System.Linq;
namespace CsharpBuddy