Skip to content

Instantly share code, notes, and snippets.

View miikka's full-sized avatar

Miikka Koskinen miikka

View GitHub Profile
@miikka
miikka / spinner.py
Last active November 3, 2015 14:57
#!/usr/bin/env python
# Like sleep(1), but shows a spinner while waiting.
import time
import sys
CHARS = '/-\\|'
def spin(delay):
@miikka
miikka / sleep.c
Last active June 11, 2022 00:53
Please have a spinner in sleep(1)
/* We present: high-quality highly accurate nanosleep with a spinner.
*
* Compile and run:
*
* gcc -shared -fPIC -o libsleep.so sleep.c
* LD_PRELOAD=./libsleep.so sleep 3
* */
#include <time.h>
@miikka
miikka / observe.js
Created November 19, 2015 17:08
Observe property reads in JavaScript
/* Recursively observe property reads of an object.
*
* Takes the target and an object for returning results. Returns the proxied
* target. Results are assigned to result.reads.
*
* Example:
*
* var target = {a: 1};
* var result = {};
* target = observeReads(target, result);
@miikka
miikka / cheatsheet.rnc
Created January 12, 2016 19:54
RELAX NG compact syntax cheat sheet
# RELAX NG compact syntax cheat sheet
# See also:
# * tutorial <http://www.relaxng.org/compact-tutorial-20030326.html>
# * spec <http://www.relaxng.org/compact-20021121.html>
# Checking a XML file:
#
# jing -c schema.rnc file.xml
#
@miikka
miikka / topology.v
Created January 15, 2016 10:25 — forked from andrejbauer/topology.v
How to get started with point-set topology in Coq. This is not actually how one would do it, but it is an intuitive setup for a classical mathematician.
(* How do to topology in Coq if you are secretly an HOL fan.
We will not use type classes or canonical structures because they
count as "advanced" technology. But we will use notations.
*)
(* We think of subsets as propositional functions.
Thus, if [A] is a type [x : A] and [U] is a subset of [A],
[U x] means "[x] is an element of [U]".
*)
Definition P (A : Type) := A -> Prop.
@miikka
miikka / schema.py
Last active November 25, 2023 20:09
Using Hypothesis to generate XML based on RELAX-NG
import string
from lxml import etree
from lxml.etree import QName
from lxml.builder import E
from hypothesis import strategies as st
NS = "http://relaxng.org/ns/structure/1.0"
from collections import defaultdict, namedtuple
import numpy as np
def visible_cap_central_angle(altitude):
earth_radius = 6371.0
return np.arctan2(np.sqrt(altitude * (altitude + 2 * earth_radius)),
earth_radius)
def hav(x):
return np.sin(x/2)**2
@miikka
miikka / example.clj
Last active August 16, 2016 10:57
clojure.spec version of ring-swagger's README example
(ns example
(:require [clojure.spec :as spec]
[ring.swagger.swagger2 :as rs]
[schema.core :as s]))
(spec/def ::id string?)
(spec/def ::name string?)
(spec/def ::street string?)
(spec/def ::city #{"tre" "hki"})
@miikka
miikka / sprite.py
Last active October 17, 2016 10:08
Generate random symmetric sprites in the terminal
#!/usr/bin/env python
# Inspired by this tweet: https://twitter.com/AtticusBones/status/787936821892317184
from __future__ import division
import atexit
import curses
import math
import random
import sys
@miikka
miikka / dne.v
Created January 26, 2017 19:58
Double negation elimination
Axiom a1 : forall A B, A -> (B -> A).
Axiom a2 : forall A B, (~B -> ~A) -> (A -> B).
Theorem dne :
forall A, ~~A -> A.
Proof.
intros A P.
generalize P.
apply a2, a2, a1, P.
Qed.