Skip to content

Instantly share code, notes, and snippets.

View bergwerf's full-sized avatar

Herman Bergwerf bergwerf

View GitHub Profile
@bergwerf
bergwerf / loaders.scss
Created June 21, 2023 15:39
Animated loaders in Sass
@mixin droplet($color, $time, $size, $scale) {
position: relative;
&::after {
content: '';
display: inline-block;
width: $size;
height: $size;
border-radius: $size;
background: $color;
@bergwerf
bergwerf / server.py
Created May 31, 2023 16:39
Minimalistic server
import io
import json
import http.server
import socketserver
HOST = "localhost"
PORT = 8080
class AnalyzerHandler(http.server.BaseHTTPRequestHandler):
def do_POST(self):
@bergwerf
bergwerf / cycles.glsl
Created January 29, 2022 16:24
Hue cycling over grayscale
// Try on: https://www.shadertoy.com/new
// With: https://github.com/andrewhills/ShadertoyCustomTextures
// https://www.shadertoy.com/view/XljGzV
vec3 hsl2rgb( in vec3 c )
{
vec3 rgb = clamp( abs(mod(c.x*6.0+vec3(0.0,4.0,2.0),6.0)-3.0)-1.0, 0.0, 1.0 );
return c.z + c.y * (rgb-0.5)*(1.0-abs(2.0*c.z-1.0));
}
@bergwerf
bergwerf / pigeons.v
Created November 10, 2020 11:07
Another attempt at an elegant pigeon-hole principle proof in Coq.
Require Import Utf8 Nat PeanoNat Lia Compare_dec.
Import Nat.
Section Pigeons.
Variable f : nat -> nat.
Variable Σ N : nat.
Hypothesis bound : ∀i, i < N -> f i < Σ.
Hypothesis overflow : Σ < N.
@bergwerf
bergwerf / primes.txt
Created August 21, 2020 21:10
Binary Turing Machine that recognizes primes
; http://morphett.info/turing/turing.html
0 * * l start1
start1 * _ l start2
start2 * 1 l start3
start3 * _ l start4
start4 * 1 r first1
first1 _ _ r first2
@bergwerf
bergwerf / bb5.go
Last active May 28, 2020 22:11
A Busy Beaver simulator and Pixmap writer
package main
import "fmt"
type tm struct {
halt int
states []state
}
type trans struct {
@bergwerf
bergwerf / demos.v
Last active May 25, 2020 10:47
Coq demos of CoInductive, Setoid, Function
(* Examples of co-induction, quotient types (setoid), custom termination *)
Require Import Coq.Init.Nat.
Require Import Coq.Unicode.Utf8.
Require Import Coq.Arith.Mult.
Require Import Coq.Arith.Compare_dec.
Require Import Coq.Classes.RelationClasses.
Require Import Coq.Classes.Morphisms.
Require Import Coq.micromega.Lia.
Import PeanoNat.Nat.
@bergwerf
bergwerf / puzzle.v
Created March 3, 2020 23:38
Is this proof fundamentally impossible in Coq? (without resorting to Sigma types)
Require Import Coq.Lists.List.
Require Import Coq.micromega.Lia.
Import ListNotations.
Arguments In {_}.
Lemma problem N (P : nat -> Prop) (Q : nat -> nat -> Prop) :
(forall n : nat, P n -> n <= N) ->
(forall n : nat, n <= N -> exists x, Q n x) ->
exists l : list nat, forall n, P n -> exists x, In x l /\ Q n x.
Proof.
@bergwerf
bergwerf / isect.v
Created March 2, 2020 23:27
Spread and fan intersections, which I removed from my intuitionistic math Coq library.
(* Spread and fan prefix intersections. *)
From intuitionism Require Import lib set seq bcp spr fan.
(* Finite sequence comparison. *)
Section FiniteCompare.
(* Check if two sequences have a shared prefix. *)
Fixpoint fcompare (s t : fseq) :=
match s, t with
@bergwerf
bergwerf / collatz.v
Created February 28, 2020 22:35
Collatz Conjecture in Coq
(* The Collatz conjecture, to illustrate reckless statements. *)
Section Collatz.
(* Collatz mapping. *)
Definition collatz_map n := if even n then div2 n else n*3+1.
(* Collatz sequence starting with n. *)
Fixpoint collatz_seq n i :=
match i with