Skip to content

Instantly share code, notes, and snippets.

View tomphp's full-sized avatar

Tom Oram tomphp

View GitHub Profile
@tomphp
tomphp / Generics.cs
Last active October 13, 2023 12:03
Generic Test
// Provided by Andrew Gibson @gooballLogic
// Set up:
// - dotnet new console
// - dotnet add package OneOf
// Implement each of the methods below so that they all compile
// There only one valid implementation for each function (apart from f5 & f6)
using OneOf;
@tomphp
tomphp / rc.py
Created October 11, 2023 14:37
Reference counting example
from collections import defaultdict
class Memory:
MEMORY = {0: None}
@staticmethod
def allocate(value):
address = max(Memory.MEMORY.keys()) + 1
Memory.MEMORY[address] = value
module LightBulb
( LightBulb
, newLightBulb
, switchOn
, switchOff
) where
import Control.Concurrent (Chan, newChan, readChan, writeChan)
import Control.Concurrent.Async (async)
import Control.Monad.Loops (iterateM_)
module LogParser exposing (..)
import Parser exposing (..)
type LogPart
= Text String
| URL String
@tomphp
tomphp / .ghcid
Created November 5, 2019 19:01
GHCID file
--command "stack ghci project:lib project:test:project-test --ghci-options='-fobject-code -Werror -Wall'" -T=main
@tomphp
tomphp / BowlingSpec.hs
Created October 26, 2019 11:51
Haskell Bowling
{-# LANGUAGE GeneralisedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase #-}
module BowlingSpec where
import Test.Hspec
import Control.Applicative ((<|>))
newtype Frame = Frame Int deriving (Num, Enum)
@tomphp
tomphp / bowling.rs
Last active October 26, 2019 10:25
Rusty Bowling
const FRAMES_IN_GAME: i32 = 10;
const PINS_IN_FRAME: i32 = 10;
const ROLLS_IN_FRAME: usize = 2;
const ROLLS_IN_STRIKE_FRAME: usize = 1;
const ROLLS_IN_SCORE_DEFAULT: usize = 2;
const ROLLS_IN_SCORE_SPARE: usize = 3;
const ROLLS_IN_SCORE_STRIKE: usize = 3;
struct Game {
scores: Vec<i32>,
type LoadedContent a
= Loading
| Success a
| Failure
type alias Model
= LoadedContent Logs
@tomphp
tomphp / Main.hs
Created June 19, 2019 18:58
Code from Success & Failure Book
{-# LANGUAGE ApplicativeDo #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE UnicodeSyntax #-}
module Main where
import Control.Lens
import Control.Monad ((>=>))
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE GADTs #-}
import Control.Monad ((>=>))
{-
-- Initial style
data Console a = GetLine String (String -> Console a)