Skip to content

Instantly share code, notes, and snippets.

View yetanotherchris's full-sized avatar
🔏
;ÿÿÿÿrules

Chris S. yetanotherchris

🔏
;ÿÿÿÿrules
View GitHub Profile
@yetanotherchris
yetanotherchris / replace-service-in-servicecollection.cs
Created October 9, 2018 11:51
Replace type in ServiceCollection for testing
public static class ServiceExtensions
{
public static ServiceCollection ReplaceWithFake<T>(this ServiceCollection services) where T : class
{
T fake = Substitute.For<T>();
var descriptor = new ServiceDescriptor(typeof(T), fake.GetType(), ServiceLifetime.Scoped);
services.Replace(descriptor);
return services;
@yetanotherchris
yetanotherchris / OptionsExtension.cs
Last active September 12, 2018 11:48
IOptions extension method to bind both IOptions<T> and T as a singleton
public static class OptionsExtensions
{
public static IServiceCollection ConfigureOptionsAndInstance<T>(this IServiceCollection services, IConfigurationSection section)
where T : class, IOptions<T>, new()
{
services.Configure<T>(section);
services.AddSingleton<T>(provider => provider.GetService<IOptions<T>>().Value);
return services;
}
@yetanotherchris
yetanotherchris / git-log.sh
Created August 3, 2018 09:53
Git log examples
# All commit history, e.g. "[2018-04-15 12:39:15 +0100] Chris S. A bit more readme"
git log --pretty=format:'[%ai] %an. %s' --abbrev-commit > commits.txt
# 5 commits
git log --pretty=format:'[%ai] %an. %s' --abbrev-commit -5 > commits.txt
@yetanotherchris
yetanotherchris / first-steps.md
Created August 1, 2018 16:42
Converting NUnit to XUnit
  • Get VS Code
  • Remove using NUnit.Framework;
  • Add using XUnit;
  • Replace all [Test] with [Fact]
  • Replace [SetUp] with a constructor
  • Replace Assert.That(actualValue, Is.EqualTo(value)); with Assert.Equal(expected, actual)
    • highlight Is.EqualTo(
    • Delete it
    • Select to the end of the line
  • Ctrl + X
@yetanotherchris
yetanotherchris / create-user-and-database.sql
Created July 31, 2018 13:02
Create a Postgres user and database through the command line, using psql.exe
psql -c "create database roadkill;" -U postgres
psql -c "CREATE USER roadkill WITH PASSWORD 'secretpassword';" -U postgres
psql -c "ALTER USER roadkill WITH SUPERUSER;" -U postgres
@yetanotherchris
yetanotherchris / appsettings.json
Last active September 28, 2023 08:32
.NET Core Examples: configuration binding and appsetting.json
{
"Smtp": {
"Host": "smtp.gmail.com",
"Port": 587,
"UseSSL": true,
"Username": "bob",
"Password": "password",
}
}
@yetanotherchris
yetanotherchris / install-vs-and-docker.ps1
Created October 27, 2017 21:17
Install Docker and Visual Studio 2017
Set-ExecutionPolicy RemoteSigned -Confirm:$false -Force
iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))
# Stop prompting in Chocolately
choco feature enable -n allowGlobalConfirmation
choco install visualstudio2017community; choco install visualstudio2017-workload-netcoretools; choco install visualstudio2017-workload-netweb; choco install docker-for-windows;
@yetanotherchris
yetanotherchris / install.ps1
Last active October 21, 2017 17:25
Installation script for tools running inside a Visual Studio 2017 VM on Azure
# Check for admin
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal( [Security.Principal.WindowsIdentity]::GetCurrent())
if ($currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) -eq $false)
{
Write-Error "Please run this scripts as an administrator"
exit 1
}
Set-ExecutionPolicy RemoteSigned -Confirm:$false -Force
iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))
@yetanotherchris
yetanotherchris / whatsapp.linq
Last active October 20, 2017 17:13
WhatsApp message statistics. Needs LinqPad to run.
<Query Kind="Program">
<Namespace>System.Globalization</Namespace>
</Query>
// Open a chat, click "..." and email to yourself (no media)
void Main()
{
var messages = new List<Message>();
string file = File.ReadAllText(@"/wapp.txt"); // c:\wapp.txt
@yetanotherchris
yetanotherchris / enable-hyperv-in-hyperv.ps1
Created October 15, 2017 09:14
Enable Hyper-V inside Hyper-V for Windows 10 Creators Edition. Run docker inside a Hyper-V VM
# Example: ./enable-hyperv-in-hyperv.ps1 -vmName "Windows 10"
param (
[Parameter(Mandatory = $true)]$vmName
)
Set-VMProcessor -VMName $vmName -ExposeVirtualizationExtensions $true
Get-VMNetworkAdapter -VMName $vmName | Set-VMNetworkAdapter -MacAddressSpoofing On
Write-Host "VM updated. Make sure your VM has dynamic memory enabled, and has 4gb or more"