Skip to content

Instantly share code, notes, and snippets.

View diekmann's full-sized avatar

Cornelius Diekmann diekmann

  • Munich, Germany
View GitHub Profile
@diekmann
diekmann / main.rs
Created March 13, 2021 20:47
Adding two natural numbers in rust the typesafe way.
trait Nat {}
#[derive(Debug, PartialEq, Copy, Clone)] enum Zero{Zero}
#[derive(Debug, PartialEq, Copy, Clone)] enum Suc<N>{Suc(N)}
impl Nat for Zero{}
impl<N: Nat> Nat for Suc<N>{}
fn add_two<N: Nat>(n: N) -> Suc<Suc<N>> { Suc::Suc(Suc::Suc(n)) }
@diekmann
diekmann / f.html
Created April 24, 2020 15:28
The worst web-technology FizzBuzz? The worst web-technology FizzBuzz so far!
<html>
<head>
<style>
/* The printing of Fizz or Buzz instead of numbers is just style. Moving the logic to CSS.*/
p:nth-child(3n){
visibility: hidden;
}
p:nth-child(3n)::before{
visibility: visible;
font-size: medium;
@diekmann
diekmann / main.py
Last active March 15, 2020 17:29
covid-19 plot
#! /usr/bin/env python3
import math
import datetime
import csv
import matplotlib.pyplot as plt
import numpy as np
t_italy = None
italy = None
@diekmann
diekmann / CSS DFA
Created November 3, 2019 18:26
A DFA implemented in CSS, telling if a number is divisible by 3
<!DOCTYPE html>
<html>
<head>
<style>
body {
counter-reset: bits; /*integer value of the binary number represented by checkboxes. */
}
@diekmann
diekmann / aesentropy.py
Created June 21, 2017 09:09
AES decryption with random keys gives unique entropy for each key (over 90% unique in test case)
#!/usr/bin/env python3
from collections import Counter
import math
from Crypto.Cipher import AES
from Crypto import Random
def multlog2(x):
if x == 0:
return 0
return x*math.log2(x)
@diekmann
diekmann / gist:74fbb137517588d210ce73c8ed7cc422
Created June 9, 2017 15:04
[draft] dump outermost page table in with 4 level paging (Linux x64 default)
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/init.h>
#include <linux/module.h>
#include <linux/printk.h>
#ifndef __x86_64__
#error "wrong arch"
#endif