Skip to content

Instantly share code, notes, and snippets.

View mbrookson's full-sized avatar

Matthew Brookson mbrookson

View GitHub Profile
@mbrookson
mbrookson / AlphabeticalOrderJsonContractResolver.cs
Created February 5, 2021 11:54
.NET Core alphabetical property name JSON serializer
public class AlphabeticalOrderJsonContractResolver : CamelCasePropertyNamesContractResolver
{
protected override IList<JsonProperty> CreateProperties(
Type type,
MemberSerialization memberSerialization
)
{
return base.CreateProperties(type, memberSerialization)
.OrderBy(p => p.PropertyName)
.ToList();
@mbrookson
mbrookson / TestInitialize to constructor.txt
Last active November 18, 2020 10:03
TestInitialize to constructor
# Remove [TestInitialize] attribute and replace Initialise method name with class name for constructor
(public\sclass\s(\w*).*((\r\n|\r|\n).*)*)\[TestInitialize\]\n.*(public\s)void\s(\w*)
(public\sclass\s(\w*).*((\r\n|\r|\n).*)*)\[TestInitialize\]\n.*(public\s)async\sTask\s(\w*)
# Replace substitutions
$1$5$2
@mbrookson
mbrookson / backup_restore_postgres.sh
Last active July 22, 2020 20:09
Backup and restore dockerised postgres database
# Backup
docker exec -t your-db-container pg_dumpall -c -U postgres > dump_$(date +"%Y-%m-%dT%H-%M-%S").sql
# Backup gzipped
docker exec -t your-db-container pg_dumpall -c -U postgres | gzip > ./tmp/dump_$(date +"%Y-%m-%dT%H-%M-%S").gz
# -------------------------------------------------------------------------------------------------------------
# Restore
cat your_dump.sql | docker exec -i your-db-container psql -U postgres
@mbrookson
mbrookson / destructuring.js
Last active July 3, 2020 09:43
JavaScript destructuring
function person() {
return { name: 'Matt', age: 25 };
}
// Object destructuring
let { name, age } = person();
// name === 'Matt'
// age === 25
@mbrookson
mbrookson / mediator.cs
Created June 17, 2020 19:31
Mediator example
using System;
using System.Collections.Generic;
using System.Linq;
public class Program
{
public class Person
{
public string Name { get; }