Skip to content

Instantly share code, notes, and snippets.

@refi64
refi64 / README.md
Last active November 29, 2023 15:54
The best GitHub README

kma

Travis CI badge Circle CI badge GitHub Actions badge Coverage badge LGTM badge npm badge pub.dev badge Download count badge

compress:{,/({y,$#x@y}t)'!t:=x}
@refi64
refi64 / main.dart
Created May 19, 2020 18:31
Dart "protected methods" via interfaces & mixins
abstract class MyType {
void doStuff();
}
mixin MyTypeHelpers {
void protectedUtilityMethod() => print('Protected method');
}
abstract class MyDerivedType implements MyType {
factory MyDerivedType.create() => MyDerivedTypeImpl();
@refi64
refi64 / sbt.k
Created July 27, 2020 01:48
Stern-brocot tree search in K
/ square root of double precision epsilon (sqrt(2^-52))
E:1.4901161193847656e-8
/ abs[x]: absolute value of x
abs::$[x>0;x;-x]
/ xeq[x;y]: tests if x and y are approximately equal (difference is <sqrt(epsilon))
xeq::E>abs x-y
/ sb[q] Stern-brocot tree search, e.g. sbt[1%3] returns (1 3)
sbt:{[q]+/({[q;LH]~xeq[q;%/+/LH]}q;{[q;L;H]$[q>%/M:L+H;(M;H);(L;M)]}[q].)/:(0 1;1 0)}
/ benchmark: