Skip to content

Instantly share code, notes, and snippets.

📈
Focusing

Chris S. yetanotherchris

📈
Focusing
Block or report user

Report or block yetanotherchris

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@yetanotherchris
yetanotherchris / OptionsExtension.cs
Last active Sep 12, 2018
IOptions extension method to bind both IOptions<T> and T as a singleton
View OptionsExtension.cs
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;
}
View git-log.sh
# 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 Aug 1, 2018
Converting NUnit to XUnit
View first-steps.md
  • 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 Jul 31, 2018
Create a Postgres user and database through the command line, using psql.exe
View create-user-and-database.sql
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 May 27, 2018
.NET Core Examples: configuration binding and appsetting.json
View appsettings.json
{
"Smtp": {
"Host": "smtp.gmail.com",
"Port": 587,
"UseSSL": true,
"Username": "bob",
"Password": "password",
}
}
@yetanotherchris
yetanotherchris / install-vs-and-docker.ps1
Created Oct 27, 2017
Install Docker and Visual Studio 2017
View install-vs-and-docker.ps1
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 Oct 21, 2017
Installation script for tools running inside a Visual Studio 2017 VM on Azure
View install.ps1
# 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 Oct 20, 2017
WhatsApp message statistics. Needs LinqPad to run.
View whatsapp.linq
<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 Oct 15, 2017
Enable Hyper-V inside Hyper-V for Windows 10 Creators Edition. Run docker inside a Hyper-V VM
View enable-hyperv-in-hyperv.ps1
# 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"
@yetanotherchris
yetanotherchris / postman-mvc-post-returns-null.md
Created Sep 29, 2017
Postman and ASP.NET MVC POST returns null
View postman-mvc-post-returns-null.md

If you are using Postman or manually calling your ASP.NET MVC REST api, and getting a null coming through this could be for various reasons:

[Route("Post")]
[HttpPost)
public string Post([FromBody] MyModel model)
{
   // do something with model
}
You can’t perform that action at this time.