Skip to content

Instantly share code, notes, and snippets.

Avatar

Harm Aarts haarts

View GitHub Profile
@haarts
haarts / main.dart
Last active Sep 1, 2020
safe money
View main.dart
abstract class Currency {
const Currency(this.precision, this.currencyCode);
final int precision;
final String currencyCode;
static List<Currency> all() {
return [Chf(), Xbt()];
}
}
@haarts
haarts / unique.dart
Last active Oct 28, 2019
A transformer to only allow unique entries. `Unique(memory: 1)` is equivalent to `distinct()`.
View unique.dart
class Unique<T> extends StreamTransformerBase<T, T> {
final int memory;
const Unique({this.memory = 10});
Stream<T> bind(Stream<T> stream) => Stream<T>.eventTransformed(
stream, (EventSink sink) => UniqueSink<T>(sink, memory: memory));
}
class UniqueSink<T> implements EventSink<T> {
final EventSink<T> _output;
final Set<T> _seen = {};
View keybase.md

Keybase proof

I hereby claim:

  • I am haarts on github.
  • I am haarts (https://keybase.io/haarts) on keybase.
  • I have a public key ASA55JuywI25AAxHvndx2p0bNN_HRUkgK3aVUOKFp9D7wQo

To claim this, I am signing this object:

@haarts
haarts / retry.dart
Created Jul 11, 2019
Elegant retries
View retry.dart
var fail = true;
int sheep() {
if (fail) {
fail = false;
throw Exception("boom!");
}
return 1;
}
@haarts
haarts / version_check.rb
Created Jun 14, 2019
Check if the versions defined in a Dart pubspec file are still up to date
View version_check.rb
require 'yaml'
require 'net/http'
require 'json'
url = 'https://pub.dev/api/packages/'
local_spec = YAML.load_file('pubspec.yaml')
local_spec["dependencies"].each do |lib, version|
if !version.is_a? String
next
end
@haarts
haarts / symbols.txt
Created Jan 3, 2019
log generated with `export LD_DEBUG=symbols`
View symbols.txt
2415: symbol=_ZNSbIwSt11char_traitsIwESaIwEE4_Rep11_S_max_sizeE; lookup in file=libffmpeg.so [0]
2415: symbol=_ZNSbIwSt11char_traitsIwESaIwEE4_Rep11_S_max_sizeE; lookup in file=/usr/lib/x86_64-linux-gnu/libasound.so.2 [0]
2415: symbol=_ZNSbIwSt11char_traitsIwESaIwEE4_Rep11_S_max_sizeE; lookup in file=/usr/lib/x86_64-linux-gnu/libcups.so.2 [0]
2415: symbol=_ZNSbIwSt11char_traitsIwESaIwEE4_Rep11_S_max_sizeE; lookup in file=/lib/x86_64-linux-gnu/librt.so.1 [0]
2415: symbol=_ZNSbIwSt11char_traitsIwESaIwEE4_Rep11_S_max_sizeE; lookup in file=/lib/x86_64-linux-gnu/libdl.so.2 [0]
2415: symbol=_ZNSbIwSt11char_traitsIwESaIwEE4_Rep11_S_max_sizeE; lookup in file=/lib/x86_64-linux-gnu/libexpat.so.1 [0]
2415: symbol=_ZNSbIwSt11char_traitsIwESaIwEE4_Rep11_S_max_sizeE; lookup in file=/usr/lib/x86_64-linux-gnu/libstdc++.so.6 [0]
2415: symbol=_ZN12v8_inspector8protocol8Debugger3API6Paused10ReasonEnum3XHRE; lookup in file=libnode.so [0]
2415: symbol=_ZN12v8_inspector
View kakrc
colorscheme zenburn
add-highlighter global/ number-lines -relative
add-highlighter global/ show-matching
hook global WinSetOption filetype=python %{
hook window InsertChar \t -group python-indent %{ exec -draft h@ }
}
hook global WinSetOption filetype=git-commit %{
autowrap-enable
View .editorconfig
root = true
# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
# 2 space indentation
[*.dart]
indent_style = space
indent_size = 2
@haarts
haarts / secp256k1.dart
Last active Jul 25, 2018
Demo secp256k1 key pair generation with PointyCastle
View secp256k1.dart
import "dart:typed_data";
import "dart:math";
import "package:pointycastle/pointycastle.dart";
import "package:pointycastle/export.dart";
import "package:pointycastle/api.dart";
import "package:pointycastle/ecc/api.dart";
import "package:pointycastle/ecc/curves/secp256k1.dart";
import "package:pointycastle/key_generators/api.dart";
import "package:pointycastle/key_generators/ec_key_generator.dart";
import "package:pointycastle/random/fortuna_random.dart";
@haarts
haarts / collections.dat
Created Feb 3, 2017
Which Java Collection is used most often?
View collections.dat
ArrayList 20870423
Stack 13799424
HashSet 3862284
Vector 3855212
LinkedList 2543036
TreeSet 589965
LinkedHashSet 366171
EnumSet 289934
LinkedBlockingQueue 207736
PriorityQueue 136294