Skip to content

Instantly share code, notes, and snippets.

View Porges's full-sized avatar
🏠
Working from home

George Pollard Porges

🏠
Working from home
View GitHub Profile
@Porges
Porges / il.fs
Last active April 9, 2017 22:58
open System.Reflection.Emit
// The reader monad (note that we use this with mutation!):
module Implicit =
type Implicitly<'i, 't> = private Implicitly of ('i -> 't)
let implicitly = Implicitly
let runImplicit impl (Implicitly f) = f impl
void Main()
{
AssertNullChecked(() => new List<int>(null));
}
public static void AssertNullChecked(Expression<Action> expr)
{
(IReadOnlyCollection<Expression>, IReadOnlyCollection<ParameterInfo>) GetArgumentsAndParameters()
{
if (expr.Body is MethodCallExpression callExp)
using System;
using System.IdentityModel.Tokens.Jwt;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using Microsoft.IdentityModel.Tokens;
namespace JWTTest
{
public static class Program
{
// Decompiled with JetBrains decompiler
// Type: BefungeProgram
// Assembly: BefungeAssembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 65A2B595-E084-42D2-81CC-A4F495D3475C
// Assembly location: C:\Users\porges\Documents\Visual Studio 2017\Projects\Befunge\Bege\bill.exe
// Compiler-generated code is shown
using System.IO;
using System.Runtime.InteropServices;
{-# LANGUAGE GADTs, RecordWildCards #-}
import Data.Monoid
data DFA a r where
DFA :: { transition :: a -> Endo s, initial :: s, result :: s -> r } -> DFA a r
run :: Foldable f => DFA a r -> f a -> r
run DFA{..} input = result (foldMap transition input `appEndo` initial)
open System
open System.Diagnostics
type InteractionF<'f> =
| Get of (string -> 'f)
| Put of string * 'f
with
static member map f = function
| Get g -> Get (f << g)
| Put (s, g) -> Put (s, f g)
@Porges
Porges / free.hs
Created May 4, 2017 07:05
Example of free monad usage in Haskell
{-# LANGUAGE DeriveFunctor #-}
module Main where
import Control.Monad
import Control.Monad.Free
data InteractionF f
= Get (String -> f)
| Put String f
@Porges
Porges / gochan.cs
Last active May 11, 2017 06:00
Go channel implementation
void Main()
{
Channels();
BufferedChannels();
ChannelDirections();
}
// Example from: https://gobyexample.com/channels
void Channels()
{
"Cheese".StartsWith("C­͏͸͹Ϳ΀΁΂΃΋΍΢ԤԥԨԩԪԫԬԭԮԯ԰՗՘ՠֈ֋֌֍֎֏֐׈׉׊׋׌׍׎׏׫׬׭׮ׯ׵׶׷׸׹׺׻׼׽׾׿؄؅؜؝ـ܎݋݌޲޳޴޵޶޷޸޹޺޻޼޽޾޿߻߼߽߾߿࠮࠯࠿࡜࡝࡟ࡠࡡࡢࡣࡤࡥࡦࡧࡨࡩࡪ࡫࡬࡭࡮࡯ࡰࡱࡲࡳࡴࡵࡶࡷࡸࡹࡺࡻࡼࡽࡾࡿࢀࢁࢂࢃࢄࢅࢆࢇ࢈ࢉࢊࢋࢌࢍࢎ࢏࢐࢑࢒࢓࢔࢕࢖࢙࢚࢛ࢗ࢘࢜࢝࢞࢟ࢠࢡࢢࢣࢤࢥࢦࢧࢨࢩࢪࢫࢬࢭࢮࢯࢰࢱࢲࢳࢴࢵࢶࢷࢸࢹࢺࢻࢼࢽࢾࢿࣀࣁࣂࣃࣄࣅࣆࣇࣈࣉ࣏࣐࣑࣒࣓࣊࣋࣌࣍࣎ࣔࣕࣖࣗࣘࣙࣚࣛࣜࣝࣞࣟ࣠࣡࣢ࣰࣱࣲࣣࣦࣩ࣭࣮࣯ࣶࣹࣺࣤࣥࣧࣨ࣪࣫࣬ࣳࣴࣵࣷࣸࣻࣼࣽࣾࣿऀॸঀ঄঍঎঑঒঩঱঳঴঵঺঻৅৆৉৊৏৐৑৒৓৔৕৖৘৙৚৛৞৤৥৻ৼ৽৾৿਀਄਋਌਍਎਑਒਩਱਴਷਺਻਽੃੄੅੆੉੊੎੏੐੒੓੔੕੖੗੘੝੟੠੡੢੣੤੥੶੷੸੹੺੻੼੽੾੿઀઄઎઒઩઱઴઺઻૆૊૎૏૑૒૓૔૕૖૗૘૙૚૛૜૝૞૟૤૥૰૲૳૴૵૶૷૸ૹૺૻૼ૽૾૿଀଄଍଎଑଒଩଱଴଺଻୅୆୉୊୎୏୐୑୒୓୔୕୘୙୚୛୞୤୥୸୹୺୻୼୽୾୿஀஁஄஋஌஍஑஖஗஘஛஝஠஡஢஥஦஧஫஬஭஺஻஼஽௃௄௅௉௎௏௑௒௓௔௕௖௘௙௚௛௜௝௞௟௠௡௢௣௤௥௻௼௽௾௿ఀఄ఍఑఩ఴ఺఻఼౅౉౎౏౐౑౒౓౔౗ౚ౛౜ౝ౞౟౤౥౰౱౲౳౴౵౶౷ಀಁ಄಍಑಩಴಺಻೅೉೎೏೐೑೒೓೔೗೘೙೚೛೜ೝ೟೤೥೰ೳ೴೵೶೷೸೹೺೻೼೽೾೿ഀഁഄ഍഑഻഼൅൉൏൐൑൒൓ൔൕൖ൘൙൚൛൜൝൞ൟ൤൥൶൷൸඀ඁ඄඗඘඙඲඼඾඿෇෈෉෋෌෍෎෕෗෠෡෢෣෤෥෦෧෨෩෪෫෬෭෮෯෰෱෵෶෷෸෹෺෻෼෽෾෿฀฻฼฽฾๜๝๞๟๠๡๢๣๤๥๦๧๨๩๪๫๬๭๮๯๰๱๲๳๴๵๶๷๸๹๺๻๼๽๾๿຀຃຅ຆຉ຋ຌຎຏຐຑຒຓຘຠ຤຦ຨຩຬ຺຾຿໅໇໌໎໏໚໛ໞໟ໠໡໢໣໤໥໦໧໨໩໪໫໬໭໮໯໰໱໲໳໴໵໶໷໸໹໺໻໼໽໾໿཈཭཮཯཰྘྽࿍࿛࿜࿝࿞࿟࿠࿡࿢࿣࿤࿥࿦࿧࿨࿩࿪࿫࿬࿭࿮࿯࿰࿱࿲࿳࿴࿵࿶࿷࿸࿹࿺࿻࿼࿽࿾࿿჆Ⴧ჈჉჊჋჌Ⴭ჎჏ჽჾჿ቉቎቏቗቙቞቟኉኎኏኱኶኷኿዁዆዇዗጑጖጗፛፜፽፾፿᎚᎛᎜᎝᎞᎟Ᏽ᏶᏷ᏸᏹᏺᏻᏼᏽ᏾᏿᚝᚞᚟ᛱᛲᛳᛴᛵᛶᛷᛸ᛹᛺᛻᛼᛽᛾᛿ᜍ᜕᜖᜗᜘᜙᜚᜛᜜᜝᜞ᜟ᜷᜸᜹᜺᜻᜼᜽᜾᜿᝔᝕᝖᝗᝘᝙᝚᝛᝜᝝᝞᝟᝭᝱᝴᝵᝶᝷᝸᝹᝺᝻᝼᝽᝾᝿៞៟៪៫៬៭៮៯៺៻៼៽៾៿᠆᠋᠌᠍᠏᠚᠛᠜᠝᠞᠟ᡸ᡹᡺᡻᡼᡽᡾᡿᢫᢬᢭᢮᢯᣶᣷᣸᣹᣺᣻᣼᣽᣾᣿ᤝᤞ᤟᤬᤭᤮᤯᤼᤽᤾᤿᥁᥂᥃᥮᥯᥵᥶᥷᥸᥹᥺᥻᥼᥽᥾᥿᦬᦭᦮᦯᧊᧋᧌᧍᧎᧏᧛᧜᧝᨜᨝᩟᩽᩾᪊᪋᪌᪍᪎᪏
var surrogate = @"([\ud800-\udbff][\udc00-\udfff])";// .NET can't handle \U10000-\u10FFFF
var c = @"([\u0009\u000a\u000d\u0020-\ud7ff\ue000-\ufffd]|"+surrogate + ")";
var s = @"([\u0020\u0009\u000d\u000a]+)";
var nameStartChar = @"([:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]|" + surrogate + ")";
var nameChar = "(" + nameStartChar + @"|[-.0-9\u00B7\u0300-\u036F\u203F-\u2040])";
var name = "(?'name'" + nameStartChar + nameChar + "*)";
var names = "(?'names'" + name + @"(\u0020" + name +")*)";
var nmtoken = "(?'nmtoken'" + nameChar + "+)";
var nmtokens = "(?'nmtokens'" + nmtoken + @"(\u0020" + nmtoken +")*)";
var pereference = "%" + name + ";";