Skip to content

Instantly share code, notes, and snippets.

View msand's full-sized avatar

Mikael Sand msand

View GitHub Profile
@msand
msand / inliner.js
Created March 3, 2019 02:48
inline css to svg attributes
const camelToKebab = camel => camel.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
/* Inline all rules from all CSS stylesheets as attributes
on all matching elements and remove class attribute */
const styles = Array.from(document.querySelectorAll("style"));
styles.forEach(styleSheet => {
Array.from(styleSheet.sheet.cssRules).forEach(rule => {
if (rule.style.display === "none") {
// Remove hidden elements
Array.from(document.querySelectorAll(rule.selectorText)).forEach(el => {
@msand
msand / .block
Last active January 27, 2019 03:26 — forked from pbeshai/.block
Animate thousands of points with Web Animations and D3
license: mit
height: 620
border: no
@msand
msand / .block
Last active January 27, 2019 03:48 — forked from hudsonb/.block
Animate thousands of points with svg and D3
license: mit
height: 620
border: no
@msand
msand / main.m
Created December 30, 2017 23:29
Test binary vs linear search on already sorted array, experiment suggests using linear up to < 16 elements
//
// main.m
// TestSearch
//
// Created by Mikael Sand on 30/12/2017.
// Copyright © 2017 Mikael Sand. All rights reserved.
//
#import <Foundation/Foundation.h>
#include <mach/mach_time.h>
@msand
msand / transform.js
Created November 14, 2017 00:07
svg transform parser in peg.js
{
const deg2rad = Math.PI / 180;
/*
a c e
( b d f )
0 0 1
*/
function multiply_matrices(l, r) {
const [al, cl, el, bl, dl, fl] = l;
@msand
msand / rinkeby
Created September 16, 2017 12:35
rinkeby
0x542753E9629cA5E2d260A9e67940812A2ddD0190
@msand
msand / svg-css-inliner-color-hexer-gradient-defs-grouper-number-formatter.js
Last active August 1, 2024 10:53
Convert Illustrator SVG export into cross-platform CSS independent mode. CSS rule and style inlining, group gradients into a definitions tag, remove elements with display set to none, make colors hex. Works with react-native-web react-native-svg and svgs to give cross-platform web and native mobile rendering of any SVG produced in Illustrator.
/*
Open console.
(Import https://raw.githubusercontent.com/MikeMcl/decimal.js/master/decimal.js first if you want/need number formatting)
Then copy & paste this + enter, to run this.
Copy console output to a NewFile.js or NewFile.jsx file.
prettier --write NewFile.js
*/
/* eslint no-console: ["error", { allow: ["log"] }] */
/* global document, Decimal*/
(() => {
module RBTree
(* Some fixes to make it work in the browser editor @ https://www.fstar-lang.org/tutorial/
*)
(*
* Red black trees, and verification of Okasaki's insertion algorithm
* (https://wiki.rice.edu/confluence/download/attachments/2761212/Okasaki-Red-Black.pdf)
*)
(* CH: how does this compare to Andrew Appel's verified RB-trees
http://www.cs.princeton.edu/~appel/papers/redblack.pdf
@msand
msand / AVL.thy
Created December 6, 2016 13:27
AVL tree Isabelle/HOL
(* Mikael Sand [email protected] *)
theory AVLproject
imports Main Int
begin
datatype 'a tree = Tip | Node "'a tree" 'a "'a tree"
primrec height :: "'a tree \<Rightarrow> nat" where
"height Tip = 0" |
"height (Node l v r) = 1 + max (height l) (height r)"