Skip to content

Instantly share code, notes, and snippets.

@themoritz
themoritz / Serialization.kt
Created January 28, 2021 00:05
Custom Serialization in Kotlin
import java.io.ByteArrayOutputStream
import java.io.ObjectInputStream
import java.io.ObjectOutputStream
import java.io.Serializable
data class Moritz(val x: Int)
data class Foo(
@Transient
var bar: Moritz,
@themoritz
themoritz / ad.rs
Created October 20, 2020 03:27
Rust Automatic Differentiation
use petgraph::algo::toposort;
use petgraph::graph::{DiGraph, NodeIndex};
use std::collections::HashMap;
#[derive(Debug, Clone)]
enum Expr {
Add { left: NodeIndex, right: NodeIndex },
Mult { left: NodeIndex, right: NodeIndex },
Var { name: String },
Sin { sub: NodeIndex },
@themoritz
themoritz / lambda-gitster-nix-shell.zsh-theme
Created August 30, 2018 05:10
zsh lambda-gitster theme with nix-shell support
local ret_status="%(?:%{$fg_bold[green]%}λ:%{$fg_bold[red]%}λ%s)%{$reset_color%}"
function get_pwd(){
git_root=$PWD
while [[ $git_root != / && ! -e $git_root/.git ]]; do
git_root=$git_root:h
done
if [[ $git_root = / ]]; then
unset git_root
prompt_short_dir=%~
@themoritz
themoritz / Transformers.hs
Created October 26, 2017 17:23
Hamburg Haskell Meetup Oct 25 2017
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
module Transformers where
import Control.Monad
data State s a = State
{ runState :: s -> (a, s)
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleContexts #-}
module Main where
import Prelude hiding (read)
import Control.Monad.Free
@themoritz
themoritz / IxFix.hs
Last active January 11, 2025 15:44
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeOperators #-}
module Indexed where
-- Natural transformation..
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
module Main where
import Control.Monad.Except