Skip to content

Instantly share code, notes, and snippets.

(* Proof that you can build foldR out of foldL *)
Require Import Arith List. Import ListNotations.
Fixpoint foldR {A : Type} {B : Type} (f : A -> B -> B) (v : B) (l : list A) : B :=
match l with
| nil => v
| x :: xs => f x (foldR f v xs)

Disable Device Enrollment Program (DEP) notification on macOS Catalina.md

With full reinstall (recommended)

   a. Boot into recovery using command-R during reboot, wipe the harddrive using Disk Utility, and select reinstall macOS

   b. Initial installation will run for approximately 1 hour, and reboot once

   c. It will then show a remaining time of about 10-15 minutes

@larsr
larsr / spectre.c
Created March 18, 2020 15:38 — forked from ErikAugust/spectre.c
Spectre example code
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#ifdef _MSC_VER
#include <intrin.h> /* for rdtscp and clflush */
#pragma optimize("gt",on)
#else
#include <x86intrin.h> /* for rdtscp and clflush */
#endif
@larsr
larsr / Dockerfile
Last active March 19, 2020 13:05
Coq docker file
# docker build -t coq .
# coqtop() (docker run --rm -v "$HOME:$HOME" -ti coq sh -c "cd $HOME ; "'coqtop $(cat ~/src/VST/_CoqProject-export)'" $@")
#FROM coqorg/coq:dev
FROM coqorg/coq:8.11.0
RUN opam init -y; \
opam repo --set-default add coq-released https://coq.inria.fr/opam/released; \
opam install -y -b coq-mathcomp-algebra coq-mathcomp-analysis coq-coquelicot coq-compcert

Creating a .so dynamic library of a haskell program and calling it from C

TLDR:

  • Export a haskell function with foreign export.
  • Create a C wrapper that calls hs_init when the library is loaded.
  • Compile the .hs and .c wrapper with ghc, linking with lHSrts-ghc8.6.5
  • Use it from C by linking as usual.

(For more details, see here.)

@larsr
larsr / aestest.md
Last active February 7, 2020 11:21

Haskell

import Crypto.Cipher.AES
import Data.ByteString.UTF8 (fromString, toString)
import Data.ByteString.Base16 (encode)


main = do
@larsr
larsr / haskell_to_llvm.sh
Created January 17, 2020 14:14
Example compiling haskell to llvm IR code and then linking it with the necessary libraries to run it. (I installed ghc and llvm with brew)
cat >demo.hs <<EOF
quicksort [] = []
quicksort (p:xs) = (quicksort lesser) ++ [p] ++ (quicksort greater)
where
lesser = filter (< p) xs
greater = filter (>= p) xs
main = print(quicksort([5,2,1,0,8,3]))
EOF
@larsr
larsr / dotnineninenine_is_one
Last active November 22, 2019 10:16
Coq proof that 0.9999999999 = 1
(* Proof that 0.9999999999... = 1 *)
Require Import Reals.
From Coquelicot Require Import Coquelicot.
Require Import Psatz.
Definition nine i := (9/10)*(1/10)^i.
Example e1: sum_n nine 3 = 9/10 + 9/100 + 9/1000 + 9/10000.
unfold nine.
@larsr
larsr / which_answer.v
Created November 21, 2019 12:01
Logic puzzle: which answer is correct?
(**
Which answer is correct?
1. All of the below.
2. None of the below.
3. All of the above.
4. At least one of the above.
5. None of the above.
6. None of the above.
@larsr
larsr / myparser2.hs
Created July 11, 2019 21:12
parser for binop expressions
import Data.Char
import Data.Functor
import Data.List
------------------------------------------------------------
import Control.Monad
import Control.Applicative
import Data.List
newtype Parser a = Parser { parse :: String -> [(a, String)]}