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
var input = "Example task section 1 section tomorrow section tagone tagtwo tagthree tagfour";
// regex altered slightly from question
var r = new Regex(@"^([\w ]+) section (\d) section (\w+) section(?: (\w+))+$");
var g = r.Match(input).Groups;
var output = $"{g[1]} !{g[2]} ^{g[3]} " +
string.Join(" ", g[4].Captures.Cast<Capture>().Select(x => "#" + x));
// output: "Example task !1 ^tomorrow #tagone #tagtwo #tagthree #tagfour"
@Porges
Porges / program.cs
Created January 16, 2017 22:33
fun with StartsWith
using System;
namespace UnicodeRulez
{
class Program
{
static void Main()
{
Console.WriteLine("Cheese".StartsWith("C­͏͸͹Ϳ΀΁΂΃΋΍΢ԤԥԨԩԪԫԬԭԮԯ԰՗՘ՠֈ֋֌֍֎֏֐׈׉׊׋׌׍׎׏׫׬׭׮ׯ׵׶׷׸׹׺׻׼׽׾׿؄؅؜؝ـ܎݋݌޲޳޴޵޶޷޸޹޺޻޼޽޾޿߻߼߽߾߿࠮࠯࠿࡜࡝࡟ࡠࡡࡢࡣࡤࡥࡦࡧࡨࡩࡪ࡫࡬࡭࡮࡯ࡰࡱࡲࡳࡴࡵࡶࡷࡸࡹࡺࡻࡼࡽࡾࡿࢀࢁࢂࢃࢄࢅࢆࢇ࢈ࢉࢊࢋࢌࢍࢎ࢏࢐࢑࢒࢓࢔࢕࢖࢙࢚࢛ࢗ࢘࢜࢝࢞࢟ࢠࢡࢢࢣࢤࢥࢦࢧࢨࢩࢪࢫࢬࢭࢮࢯࢰࢱࢲࢳࢴࢵࢶࢷࢸࢹࢺࢻࢼࢽࢾࢿࣀࣁࣂࣃࣄࣅࣆࣇࣈࣉ࣏࣐࣑࣒࣓࣊࣋࣌࣍࣎ࣔࣕࣖࣗࣘࣙࣚࣛࣜࣝࣞࣟ࣠࣡࣢ࣰࣱࣲࣣࣦࣩ࣭࣮࣯ࣶࣹࣺࣤࣥࣧࣨ࣪࣫࣬ࣳࣴࣵࣷࣸࣻࣼࣽࣾࣿऀॸঀ঄঍঎঑঒঩঱঳঴঵঺঻৅৆৉৊৏৐৑৒৓৔৕৖৘৙৚৛৞৤৥৻ৼ৽৾৿਀਄਋਌਍਎਑਒਩਱਴਷਺਻਽੃੄੅੆੉੊੎੏੐੒੓੔੕੖੗੘੝੟੠੡੢੣੤੥੶੷੸੹੺੻੼੽੾੿઀઄઎઒઩઱઴઺઻૆૊૎૏૑૒૓૔૕૖૗૘૙૚૛૜૝૞૟૤૥૰૲૳૴૵૶૷૸ૹૺૻૼ૽૾૿଀଄଍଎଑଒଩଱଴଺଻୅୆୉୊୎୏୐୑୒୓୔୕୘୙୚୛୞୤୥୸୹୺୻୼୽୾୿஀஁஄஋஌஍஑஖஗஘஛஝஠஡஢஥஦஧஫஬஭஺஻஼஽௃௄௅௉௎௏௑௒௓௔௕௖௘௙௚௛௜௝௞௟௠௡௢௣௤௥௻௼௽௾௿ఀఄ఍఑఩ఴ఺఻఼౅౉౎౏౐౑౒౓౔౗ౚ౛౜ౝ౞౟౤౥౰౱౲౳౴౵౶౷ಀಁ಄಍಑಩಴಺಻೅೉೎೏೐೑೒೓೔೗೘೙೚೛೜ೝ೟೤೥೰ೳ೴೵೶೷೸೹೺೻೼೽೾೿ഀഁഄ഍഑഻഼൅൉൏൐൑൒൓ൔൕൖ൘൙൚൛൜൝൞ൟ൤൥൶൷൸඀ඁ඄඗඘඙඲඼඾඿෇෈෉෋෌෍෎෕෗෠෡෢෣෤෥෦෧෨෩෪෫෬෭෮෯෰෱෵෶෷෸෹෺෻෼෽෾෿฀฻฼฽฾๜๝๞๟๠๡๢๣๤๥๦๧๨๩๪๫๬๭๮๯๰๱๲๳๴๵๶๷๸๹๺๻๼๽๾๿຀຃຅ຆຉ຋ຌຎຏຐຑຒຓຘຠ຤຦ຨຩຬ຺຾຿໅໇໌໎໏໚໛ໞໟ໠໡໢໣໤໥໦໧໨໩໪໫໬໭໮໯໰໱໲໳໴໵໶໷໸໹໺໻໼໽໾໿཈཭཮཯཰྘྽࿍࿛࿜࿝࿞࿟࿠࿡࿢࿣࿤࿥࿦࿧࿨࿩࿪࿫࿬࿭࿮࿯࿰࿱࿲࿳࿴࿵࿶࿷࿸࿹࿺࿻࿼࿽࿾࿿჆Ⴧ჈჉჊჋჌Ⴭ჎჏ჽჾჿ቉቎቏቗቙቞቟኉኎኏኱኶኷኿዁዆዇዗጑጖጗፛፜፽፾፿᎚᎛᎜᎝᎞᎟Ᏽ᏶᏷ᏸᏹᏺᏻᏼᏽ᏾᏿᚝᚞᚟ᛱᛲᛳᛴᛵᛶᛷᛸ᛹᛺᛻᛼᛽᛾᛿ᜍ᜕᜖᜗᜘᜙᜚᜛᜜᜝᜞ᜟ᜷᜸᜹
@Porges
Porges / 00-identifier.cs
Created January 18, 2017 04:52
Code for the "A type for every concept" post
struct Identifier
: IEquatable<Identifier>
{
private static StringComparer Comparer
= StringComparer.OrdinalIgnoreCase;
public Identifier(string value)
{
Value = value;
}
@Porges
Porges / 00-system.fs
Last active February 17, 2017 11:59
Code for "Model based testing with F# & FsCheck"
[<Struct>]
type UserId = UserId of string
type User = { id : UserId ; name : string ; age : int }
type IUserOperations =
abstract member AddUser : User -> unit
abstract member GetUser : UserId -> Option<User>
abstract member DeleteUser : UserId -> unit
abstract class State
{
public abstract bool IsFinalState { get; }
public abstract bool IsValidTransition(State next);
public abstract override string ToString();
public static State NotStarted { get; } = new NotStartedT();
public static State Running { get; } = new RunningT();
public static State Errored { get; } = new ErroredT();
public static State Completed { get; } = new CompletedT();
@Porges
Porges / flags.cs
Last active February 2, 2017 03:09
En-flags any (sane) enum
void Main()
{
Flags<Color> colors = new Flags<Color>();
Console.WriteLine(colors);
colors.Set(Color.Red);
Console.WriteLine(colors);
colors.Set(Color.White);
Console.WriteLine(colors);
}
ref class Foo
{
public:
!Foo()
{
Console::WriteLine("I'm being finalized!");
}
~Foo()
{
@Porges
Porges / static_di.cs
Last active March 23, 2017 03:31
The only dependency injection framework you'll ever need
using System;
using System.Collections.Generic;
namespace StaticDependencyRegistration
{
public static class Program
{
public static void Main()
{
var rand = Register.PerCaller(() => new Random(Guid.NewGuid().GetHashCode()));
module SafeIL
open System
open System.Reflection.Emit
open System.Runtime.CompilerServices
open System.Runtime.InteropServices
open System.Reflection
open Microsoft.FSharp.Quotations
open Microsoft.FSharp.Quotations.Patterns
open Microsoft.FSharp.Quotations.DerivedPatterns
#include <Windows.h>
#include <array>
#include <iostream>
#include <exception>
[[noreturn]] void throw_last_error() {
throw std::system_error{static_cast<int>(GetLastError()), std::system_category()};
}