Skip to content

Instantly share code, notes, and snippets.

@opqdonut
opqdonut / a10n.clj
Last active April 11, 2024 09:38
a10n.clj
(ns a10n
(:require [clojure.set :as set]
[clojure.string :as str]))
(defn i4t [t2e w2d val]
(if (empty? w2d)
(assoc t2e :end val)
(update t2e
(first w2d)
i4t (rest w2d) val)))
@opqdonut
opqdonut / README.md
Last active February 1, 2024 06:58
Python-Clojure communication with msgpack-over-udp

Python-Clojure communication with msgpack-over-udp

Install deps & start the python broadcast:

python -m venv venv
. ./venv/bin/activate
pip install -r requirements.txt
python broadcast.py
@opqdonut
opqdonut / unparse.clj
Created March 27, 2023 07:02
unparsing in clojure
(declare unparse)
(defn unparse-args [lang args]
(cond
(map? (first args))
(update-vals (first args) (partial unparse lang))
:else
(mapv (partial unparse lang) args)))
(defn unparse [lang data]
@opqdonut
opqdonut / deps.edn
Created June 1, 2022 11:31
Clojure structured logging via Log4J2
{:deps {org.apache.logging.log4j/log4j-api {:mvn/version "2.17.2"}
org.apache.logging.log4j/log4j-core {:mvn/version "2.17.2"}
org.apache.logging.log4j/log4j-layout-template-json {:mvn/version "2.17.2"}
org.apache.logging.log4j/log4j-slf4j18-impl {:mvn/version "2.17.2"}}}
@opqdonut
opqdonut / Fix.hs
Created February 13, 2022 15:27
ASTs with Functor fixpoints
{-# LANGUAGE DeriveFunctor, StandaloneDeriving #-}
import Data.Functor.Classes (Show1)
data ExprFunctor a = Literal Int | Plus a a | Times a a
deriving (Show, Functor)
data LineNumber a = LineNumber Int a
deriving (Show, Functor)
@opqdonut
opqdonut / card
Created December 21, 2021 07:51
Christmas card in Clojure
;;Merry Christmas from
;;Metosin! Run this
;;hand-baked Clojure
;;cookie to find our
;;wish for this holiday
(reduce reduce reduce[,
[reduce[comp][eval,,,,,
replace]][{\e,,,,,,,,,,
(comment)\h,,,,,,,,,,,,
assoc\i,,,,,,,,,,,,,,,,
@opqdonut
opqdonut / kortti
Created December 17, 2021 11:35
Clojurellinen joulukortti
;;Rauhaisaa joulua ja
;;tulevaa vuotta! Alla
;;pala käsinleivottua
;;clojurekoodia. Nauti!
(reduce reduce reduce[,
[reduce[comp][eval,,,,,
replace]][{\i,,,,,,,,,,
(comment)\ä,,,,,,,,,,,,
assoc\t,,,,,,,,,,,,,,,,
str},,,,,,,,,,,,,,,,,,,
@opqdonut
opqdonut / Day8.hs
Created December 10, 2021 05:55
Advent of Code 2021 Day 8
module Day8 where
import Data.List
parseLine l = (map sort $ take 10 w, map sort $ drop 11 w)
where w = words l
input = map parseLine . lines <$> readFile "input.8"
part1 i =
@opqdonut
opqdonut / Day7.hs
Created December 9, 2021 15:25
Advent of Code 2021 Day 7
module Day7 where
import Data.List
parse :: String -> [Int]
parse s = read ("["++s++"]")
input = parse <$> readFile "input.7"
example = [16,1,2,0,4,2,7,1,2,14]
@opqdonut
opqdonut / Day6.hs
Created December 9, 2021 06:28
Advent of Code 2021, Day 6
module Day6 where
import Debug.Trace
import Data.Array
step = concatMap u
where u 0 = [6,8]
u n = [n-1]
fishnaive init d = length (iterate step [init] !! d)