Skip to content

Instantly share code, notes, and snippets.

View msgodf's full-sized avatar

Mark Godfrey msgodf

View GitHub Profile
@msgodf
msgodf / aoc2022-day1-puzzle1.tf
Created December 3, 2022 14:43
Day 1, Puzzle 1 of AOC 2022
locals {
most_calories = reverse([for elf_calories in sort([for elf_calories in split(" ", replace(file("input1.txt"), "\n", " ")) : format("%08d", sum([for food_calories in split(" ", elf_calories) : food_calories == "" ? 0 : parseint(food_calories, 10)]))]) : tonumber(elf_calories)])[0]
}
output "answer" {
value = local.most_calories
}
@msgodf
msgodf / sl2018.md
Last active September 28, 2018 19:36
Strange Loop 2018
@msgodf
msgodf / pwlconf2018.md
Last active September 27, 2018 14:08
PWLConf 2018 notes

Computer-aided Concurrent Programming - Roopsha Samanta

https://pwlconf.org/2018/roopsha-samanta/

Clarke and Emerson - Design and Synthesis of Sychnronization Skeletons using Branching-Time Temporal logic - Workshop on Logics of Programs (1981)

Processes are Finite-state synchronization skeletons - supress details about synchronization Communication model: Shared memory, interleaving based - one thread takes a step at a time Specification: Temporal logic Synchronization: Guarded commands

@msgodf
msgodf / Main.hs
Last active September 29, 2017 20:42
Example of Eta code that gives `java.lang.VerifyError: Bad type on operand stack` error.
{-# LANGUAGE FlexibleContexts #-}
module Main where
import Java
import Java.Do
main :: IO ()
main = putStrLn $
mconcat $
fmap (\x -> let _ = x :: JInteger in show x) $
@msgodf
msgodf / construct-based-on-fields.purs
Created January 11, 2017 17:12
An attempt to create a different instance of a type depending on the presence of a field in the foreign (JS) object
data Sh = Sh1 {name :: String} | Sh2 {name :: String, age :: Int}
instance shIsForeign :: IsForeign Sh where
read x = do
name <- readProp "name" x
case (readProp "age" x) of
Left _ -> pure $ Sh1 {name:name}
Right age -> pure $ Sh2 {name: name, age: age}
frug :: Foreign -> String
@msgodf
msgodf / algorithms-to-live-by.md
Last active June 19, 2023 03:40
Notes on Algorithms to Live By by Brian Christian and Tom Griffiths

Done

  • Compile AmiTCP example with only -lsocket
  • Setup nginx on rpi to share files between Amiga and rpi

Todo

  • Try opening v3 of bsdsocket.library and see whether httpget still works.
  • Get a working version of curl on the Amiga.
  • Use AmiTCP specific functions, not just bsdsocket.library ones
@msgodf
msgodf / wag_protocol.clj
Created April 21, 2016 07:34
A brief example of protocols and records in Clojure
;; A protocol with a single method
(defprotocol Waggable
(wag [x]))
;; A record that implements that protocol
(defrecord Dog [name]
Waggable
(wag [x]
(prn (str (:name x)
" wagged their tail"))))
@msgodf
msgodf / ngram.clj
Created April 20, 2016 19:39
A rough solution to Richard's most common phrase problem.
(let [input (take 1000 (repeatedly #(rand-int 10)))
n 3]
(take 10
(reverse (sort-by second
(frequencies (mapcat #(partition n (drop % input))
(range n)))))))
NB. Turn on tree formatting of sentences:
(9!:3) 4
1;2;3;4
NB. ┌─┬─┬─┬─┐
NB. │1│2│3│4│
NB. └─┴─┴─┴─┘