Skip to content

Instantly share code, notes, and snippets.

View ConnorBaker's full-sized avatar
⚱️
burnt out

Connor Baker ConnorBaker

⚱️
burnt out
  • Costa Mesa, CA
  • 19:01 (UTC -07:00)
View GitHub Profile
@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 }
@ConnorBaker
ConnorBaker / het-list-of-transforms.md
Created August 8, 2020 15:53
Heterogeneous list of transformations

Suppose that you have a list of transformations you want to apply to some starting value, like a pipeline.

Ideally, we could define something in the shape of a list:

transformers :: Pipeline
transformers = [ f0 :: a0 -> a1
               , f1 :: a1 -> a2
               , f2 :: a2 -> a3
 , ...

Setup the minimum working example:

stack new mwe simple --resolver lts

Add the data Test to src/main.hs:

module Main where
module Main where
import Control.Arrow
data Polygon = Polygon { xCoords :: [Double], yCoords :: [Double], desiredArea :: Double } deriving (Eq, Show)
-- Some of the inputs aren't valid Haskell floating point numbers (they don't
-- have a leading zero) so we fix that.
sanitize :: String -> String
sanitize s@('.' : ss) = '0' : s
ffmpeg -i in.mp4 -c:v libx265 -preset placebo -x265-params "--rc-lookahead=250" -crf 36 -tune animation -c:a libopus -b:a 32k -vbr on -frame_duration 60 -application voip -strict experimental out.mkv
@ConnorBaker
ConnorBaker / Substitution.rs
Last active May 25, 2020 23:46
Solution to https://open.kattis.com/problems/substitution (fails second secret test case)
use std::io::{self, BufRead};
fn main() {
// Get the input as an iterator
// Transforms each line of input, a string containing a sequence of numbers
// (indexed from one) into a vector of i64, all indexed from zero
let stdin = io::stdin();
let is =
stdin
.lock()
@ConnorBaker
ConnorBaker / Substitution.java
Last active May 25, 2020 23:48
Solution to https://open.kattis.com/problems/substitution (fails second secret test case)
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Iterator;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Stream;
import static java.util.stream.Collectors.toList;
public class Main {
@ConnorBaker
ConnorBaker / Substitution.hs
Last active May 25, 2020 19:38
Solution to https://open.kattis.com/problems/substitution (fails second secret test case)
module Main where
import Prelude
import Control.Arrow
import Data.List.Split ( chunksOf )
import Data.Maybe ( fromJust )
import qualified Data.ByteString.Lazy.Char8 as C
import qualified Data.Vector.Unboxed as V
-- Zero index