Skip to content

Instantly share code, notes, and snippets.

View foo.fs
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 Mar 31, 2021
Install .NET Core Side By Side on Linux
View instructions.md

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

View output.log
-- 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 Oct 17, 2017 — forked from orhanveli/ToDynamic.cs
Object or Array to Dynamic in C#
View ToDynamic.cs
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 ());
View helloworld-assembler.as
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 Sep 13, 2016
VSCode tasks.json for building, restoring, executing tests on OSX with .Net Core
View info.md

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

View HttpClientExtensions.cs
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 Mar 29, 2017
How to use ASP.Net Core Cookie Middleware and sign the user in within a Nancy module
View AuthenticationModule.cs
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"));
View Startup1.cs
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");
@jchannon
jchannon / info.md
Created Jul 12, 2016
Run dotnet build on all projects in your folder hierarchy
View info.md

CMD+Shift+ in VSCode to run build task. If not configured VSCode will prompt you to choose a build system, choose CoreCLR, then paste the above json in.

This works on the Nancy code base where the folder structure is:

.
./src/Nancy/
./src/Nancy.Validation.FluentValidation/
./samples/Nancy.Demo.Hosting.Kestrel/
./tests/Nancy.Tests/