Skip to content

Instantly share code, notes, and snippets.

@mrange
mrange / 0_README.md
Last active April 22, 2022 13:36
Inferring C# from JSON with T4

C# from JSON in T4

A microblog with minimal prose and maximum amount of code

Inspired by the release notes in VS about "copy JSON to C#" I tinkered with making a T4 template to do so.

The T4 template uses some new C# language feautures + System.Text.Json so it won't work with T4 bundled with Visual Studio (still on .NET framework).

However it works fine from command line but you need to use a build of dotnet that support raw string literals. The version on my machine is 6.0.300-preview.22204.3

@mrange
mrange / 0.md
Last active March 26, 2023 11:58
F# Advent 2020, Dec 6 - Church Encoded Lists

F# Advent 2020, Dec 6 - Church Encoded Lists

Introduction

The purpose of abstraction is not to be vague, but to create a new semantic level in which one can be absolutely precise

Edsger W. Dijkstra

This is my contribution to F# Advent Calendar in English. Thanks to Sergey Tihon for making sure this happens every year.

{-# LANGUAGE DeriveFunctor #-}
module Main where
type Algebra f a = f a -> a
type Coalgebra f a = a -> f a
newtype Fix f = In { out :: f (Fix f) }
@JohnRoos
JohnRoos / Invoke-RestMethod with cookie and header.ps1
Last active April 15, 2024 06:57
Invoke-RestMethod with cookies and headers
@obscuresec
obscuresec / dirtywebserver.ps1
Created May 18, 2014 15:36
Dirty PowerShell Webserver
$Hso = New-Object Net.HttpListener
$Hso.Prefixes.Add("http://+:8000/")
$Hso.Start()
While ($Hso.IsListening) {
$HC = $Hso.GetContext()
$HRes = $HC.Response
$HRes.Headers.Add("Content-Type","text/plain")
$Buf = [Text.Encoding]::UTF8.GetBytes((GC (Join-Path $Pwd ($HC.Request).RawUrl)))
$HRes.ContentLength64 = $Buf.Length
$HRes.OutputStream.Write($Buf,0,$Buf.Length)
@ahammar
ahammar / RebindableIf.hs
Created May 11, 2012 04:15
Example of overloading if-then-else in Haskell
{-# LANGUAGE RebindableSyntax #-}
import Prelude
data Height = Tall | Short
class IfThenElse b where
ifThenElse :: b -> a -> a -> a
instance IfThenElse Bool where