Skip to content

Instantly share code, notes, and snippets.

View ConnorBaker's full-sized avatar

Connor Baker ConnorBaker

  • Costa Mesa, CA
  • 09:04 (UTC -07:00)
View GitHub Profile
{-# LANGUAGE TemplateHaskell #-}
module Tasty.Runners.Buildkite.History where
import Tasty.Runners.Buildkite.Span ( Span )
import Data.Aeson (defaultOptions, camelTo2)
import Data.Aeson.TH (deriveJSON, Options (fieldLabelModifier))
data History = History {
@ConnorBaker
ConnorBaker / run.sh
Created March 16, 2022 15:30
Command to find which nixpkg derivation support `withPackages` or `withPlugins`
rg "(withPackages *=)|(withPlugins *=)" --ignore-case --glob '*.nix'
fst = (a) -> (b) -> a
snd = (a) -> (b) -> b
_Pair2 = (a) -> (b) -> (p2) -> p2(a)(b)
show_pair = (p2) -> p2((a) -> (b) -> "(${a}, ${b})")
test_p2 = _Pair2('A')('B')
// (A, B)
println(show_pair(test_p2))
// A
println(test_p2(fst))
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE RankNTypes #-}
module Main where
import Prelude hiding (Maybe (..), concat, fst, head, snd, tail)
-- Church encoding of pair2s
newtype Pair2 a b
= MkPair2
@ConnorBaker
ConnorBaker / reverse.hs
Created January 15, 2021 00:29
Reversing a list in O(n) time with Haskell's foldr
reverse :: [α] -> [α]
reverse as = foldr f id as []
where
f :: α -- Element a to cons to as
-> ([α] -> β) -- Function f which operates on a list
-> [α] -- List as to prepend a to
-> β -- Result of applying function to a : as
f = flip (.) . (:)
-- Application
@ConnorBaker
ConnorBaker / Main.hs
Last active October 23, 2020 02:08
Some work on permutations for abstract algebra
module Main where
import qualified Data.Foldable as Foldable
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import Data.Set (Set)
-- Follow the path a value takes through multiple permutations.
-- If the value is not in the permutation, it is unchanged -- it is fixed.
trace :: Ord a => Map a a -> Map a a -> a -> a
@ConnorBaker
ConnorBaker / Main.hs
Last active September 21, 2020 02:24
Find cyclic subgroups of finite order of groups with integer elements under modular multiplication
{-# LANGUAGE RecordWildCards #-}
module Main where
data Solution = Solution
{ remainder :: Integer
, element :: Integer
, power :: Integer
}
instance Show Solution where
@ConnorBaker
ConnorBaker / Main.cry
Created September 3, 2020 03:35
Cryptol program to prove for fixed-lengths that the PRG demonstrated in class is bad
module Main where
// Generates a 2d list of zero-indexed indices of an nxn matrix.
twoDimIndices : {n} (fin n, 1 <= n) => [n][n](Integer, Integer)
twoDimIndices = [ [ (a,b) | a <- [0 .. n-1] ] | b <- [0 .. n-1] ]
// Transforms an n-bit array into a 2d nxn-bit array.
// The (i,j)-th element of the 2d nxn-bit array is the value of the i-th and
// j-th bits of the n-bit array XOR'd together.
gen : {n} (fin n, 2 <= n) => [n] -> [n * n]
module Main where
import Data.Bits
nonDiagIndices :: Int -> [(Int, Int)]
nonDiagIndices n = [(a,b) | a <- [0 .. n-1], b <- [0..n-1], a /= b]
gen :: [Bool] -> [Bool]
gen ss = ws
where
@ConnorBaker
ConnorBaker / permutationGroup.hs
Last active August 31, 2020 16:08
Permutation group of endomorphisms on the set {1,2,3}
{-# LANGUAGE RecordWildCards #-}
module Main where
data Set = Set { first :: Int
, second :: Int
, third :: Int
} deriving (Eq, Show)
data Permutation = Permutation { mapping :: Set -> Set
, name :: String }