Skip to content

Instantly share code, notes, and snippets.

@jchannon
jchannon / foo.fs
Last active January 1, 2023 19:30
type System.Int32 with
member x.DisplayWithSuffix() =
let f = x.ToString()
let defaultVal = f + "th"
let mutable result = ""
result <- if f.EndsWith("11") then f + "th" else defaultVal
result <- if f.EndsWith("12") then f + "th" else defaultVal
result <- if f.EndsWith("13") then f + "th" else defaultVal
result <- if f.EndsWith("1") then f + "st" else defaultVal
type LogLevel =
| Error
| Warning
| Info
let log (level:LogLevel) message = // LogLevel -> string -> unit
printfn "[%A]: %s" level message
()
log Error "Curried function"
@jchannon
jchannon / instructions.md
Last active March 31, 2021 18:13
Install .NET Core Side By Side on Linux

dotnet-install

Add the below alias to be used in your terminal

alias dni='curl https://dotnet.microsoft.com/download/dotnet-core/scripts/v1/dotnet-install.sh -o ~/.dotnet/dotnet-install.sh -s | chmod +x ~/.dotnet/dotnet-install.sh | ~/.dotnet/dotnet-install.sh'

Execute the below command to see possible options

dni --help

-- Message #0
-----------------------------------------------------------------
ETW collector internal error
ETW Collector error
[location] = c:\build agent\work\9f8acdb7e480c131\profiler\kernel\windows\native\solution\core\src\bridges\etw\etw_bridge.cpp(101)
[function] = enum jb::profiler::etw_bridge::loop_executor::state __cdecl jb::profiler::etw_bridge::poll_etw_state(void)
[hresult] = adab0000
-----------------------------------------------------------------
@jchannon
jchannon / ToDynamic.cs
Created October 17, 2017 19:15 — forked from orhanveli/ToDynamic.cs
Object or Array to Dynamic in C#
public static class Extensions
{
public static dynamic ToDynamic(this object value)
{
if (value.IsListOrArray ()) {
var list = new List<ExpandoObject> ();
IEnumerable enumerable = value as IEnumerable;
foreach (object o in enumerable) {
list.Add (o.ToDynamic ());
BITS 32
org 0x08048000
ehdr: ; Elf32_Ehdr
db 0x7F, "ELF", 1, 1, 1, 0 ; e_ident
times 8 db 0
dw 2 ; e_type
dw 3 ; e_machine
dd 1 ; e_version
@jchannon
jchannon / info.md
Last active September 13, 2016 11:44
VSCode tasks.json for building, restoring, executing tests on OSX with .Net Core

Info

This will require OSX and ZSH installed.

For tests it will require your directory name to match your namespace for tests as it uses the directory name to pass the namespace to xunit

public static class HttpClientExtensions
{
public static T Get<T>(this HttpClient client, string url)
{
var response = client.GetAsync(url).Result;
var content = response.Content.ReadAsStringAsync().Result;
return JsonConvert.DeserializeObject<T>(content);
}
public static HttpResponseMessage PostAsJson(this HttpClient client, string url)
@jchannon
jchannon / AuthenticationModule.cs
Last active March 29, 2017 12:40
How to use ASP.Net Core Cookie Middleware and sign the user in within a Nancy module
public class AuthModule : NancyModule
{
public AuthModule()
{
Post("/login", async _ =>
{
var myclaims = new List<Claim>(new Claim[] { new Claim("Id", "SOME USER ID FROM SOMEWHERE!!") });
var claimsPrincipal = new ClaimsPrincipal(new ClaimsIdentity(myclaims, "MyCookieMW"));
public void Configure(IApplicationBuilder app)
{
app.UseOwin(x =>
{
//Use Owin here
x.UseFirstPipelineMWThatIsOwin();
//Use ASP.Net Core pipeline inside UseOwin
app.Use((context, next) => {
context.Request.Headers.Add("CUSTOM", "BOB");