Skip to content

Instantly share code, notes, and snippets.

View ericsampson's full-sized avatar

Eric Sampson ericsampson

View GitHub Profile
using System;
using System.Collections.Generic;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;
using Microsoft.Extensions.DependencyInjection;
var config = new ConfigurationBuilder()
.AddInMemoryCollection(new Dictionary<string, string>() { { "Param", "yay!" } })
.Build();
@ericsampson
ericsampson / GitTricks
Created March 19, 2021 16:04
Git tips and tricks
1) Viewing only main/master "linear commit history" as if you'd done squash merges, while actually using merge commits in order to maintain feature branch commit history:
https://stackoverflow.com/questions/60796729/keep-commits-in-feature-branch-after-squash-merge-to-master
https://marcgg.com/blog/2015/08/04/git-first-parent-log/
2) Ignoring local changes to file:
git update-index --skip-worktree $FILE
@ericsampson
ericsampson / ConfigurationBinder.md
Last active January 8, 2021 22:20
C# Configuration Binding tips and tricks
@ericsampson
ericsampson / dotNetIssuesOfNote
Last active March 16, 2022 02:28
.NET issues that I'm tracking
C# vNext language feature implementation status
https://github.com/dotnet/roslyn/blob/main/docs/Language%20Feature%20Status.md
C# vNext Working Themes
https://github.com/dotnet/csharplang/issues/4144
RequiredProperties
https://github.com/dotnet/csharplang/issues/3630
@ericsampson
ericsampson / dotNetTipsAndTricks
Last active December 5, 2020 19:15
Key .NET tips and tricks aka note to self.
How to create NuGet packages that include multiple DLLs:
https://josef.codes/dotnet-pack-include-referenced-projects/
@ericsampson
ericsampson / DownloadShows.cs
Created November 11, 2020 04:21
C#9 version of deno syntax episode downloader
using System; using System.Net; using System.IO;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Linq;
using Refit;
const string showList = "https://syntax.fm/api";
static async Task<List<Show>> getShowList() {
var syntaxApi = RestService.For<ISyntaxApi>(showList);
@ericsampson
ericsampson / ServiceWithOptionsExample.cs
Last active November 15, 2020 19:22
Configuration pattern and ConfigureServices
// I have a service that needs to be initialized with a FooOptions and then added to the DI container.
// I also want to have IOptions<FooOptions> in the DI container to allow injection in other methods.
// How should I write my AddFoo extension method to support this?
public void ConfigureServices(IServiceCollection services)
{
services.AddFoo(fooOptions =>
{
configuration.GetSection("FooOptions").Bind(fooOptions)
fooOptions.param = "override";
@ericsampson
ericsampson / RecordsCustomEquality.cs
Created October 10, 2020 17:50
C#9 Records with custom Equality
Rec a = new Rec{myInt = 1, myStr = "test"};
Rec b = a;
System.Console.WriteLine(a == b);
public record Rec()
{
public int myInt;
public string myStr;
@ericsampson
ericsampson / keybase.md
Created February 5, 2016 17:00
Keybase proof

Keybase proof

I hereby claim:

  • I am ericsampson on github.
  • I am erics (https://keybase.io/erics) on keybase.
  • I have a public key whose fingerprint is 4E22 3DE1 A252 4DFC 31CD B662 E652 4404 2438 7DCF

To claim this, I am signing this object:

--This script MUST be named "Switch to <User>.scpt", where <User> is the name of the user to switch to.
--You must first make a password item (a.k.a. a key) for the other user's password using Keychain Access,
--and call it "<user>", where "<user>" is the other user's name.the field "Kind" must be "User Login" (without quotes).
--The script assumes that you make this key in your login.keychain, which is the default one.
--The first time you run this script, you will be prompted to allow Keychain Scripting to access the password of the key.
--This script requires "Enable access for assistive devices" to be enabled in the Universal Access system preference pane.
set username to word -1 of my findReplace(".scpt", "", (path to me as text))
-- Invoke Fast User Switching. The `id -ur username` part gets the uid number that corresponds to the username and substitutes it at the end of the CGSession command