Skip to content

Instantly share code, notes, and snippets.

View munificent's full-sized avatar

Bob Nystrom munificent

View GitHub Profile
@munificent
munificent / jamuary.dart
Created January 22, 2022 16:10
A script to help me pick gear to use for synth jams
import 'dart:math';
final gear = [
Machine('Guitar', 'sample'),
Machine('Piano', 'sample'),
Machine('YouTube', 'sample'),
Machine('Digitakt', 'synth sequencer fx'),
Machine('Digitone', 'synth sequencer fx'),
Machine('Peak', 'synth fx'),
Machine('DrumBrute Impact', 'drums'),
@munificent
munificent / field_initialization.dart
Created December 3, 2021 00:15
Script to analyze constructors and fields in Dart classes.
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:analyzer/dart/ast/ast.dart';
import 'package:scrape/scrape.dart';
void main(List<String> arguments) {
Scrape()
..addHistogram('Constructor type')
..addHistogram('Constructor name')
diff --git a/dev/benchmarks/macrobenchmarks/lib/src/web/bench_picture_recording.dart b/dev/benchmarks/macrobenchmarks/lib/src/web/bench_picture_recording.dart
index 187f160..e6e7584 100644
--- a/dev/benchmarks/macrobenchmarks/lib/src/web/bench_picture_recording.dart
+++ b/dev/benchmarks/macrobenchmarks/lib/src/web/bench_picture_recording.dart
@@ -39,7 +39,7 @@ class BenchPictureRecording extends RawRecorder {
paragraph = (ParagraphBuilder(ParagraphStyle())
..addText('abcd edfh ijkl mnop qrst uvwx yz'))
.build()
- ..layout(const ParagraphConstraints(width: 50));
+ ..layout(const ParagraphConstraints(width: 50));
@munificent
munificent / cascades.diff
Created June 14, 2021 19:45
Diff of all of the changes from https://github.com/dart-lang/dart_style/pull/1033 on a corpus of pub packages
diff --git a/_fe_analyzer_shared-14.0.0/lib/src/testing/id_generation.dart b/_fe_analyzer_shared-14.0.0/lib/src/testing/id_generation.dart
index dd3fdb7e3..db315d985 100644
--- a/_fe_analyzer_shared-14.0.0/lib/src/testing/id_generation.dart
+++ b/_fe_analyzer_shared-14.0.0/lib/src/testing/id_generation.dart
@@ -153,7 +153,9 @@ List<Annotation> _computeAnnotations<T>(
suffix);
}
- Set<Id> idSet = {}..addAll(idValuePerId.keys)..addAll(actualDataPerId.keys);
+ Set<Id> idSet = {}
@munificent
munificent / blanks.dart
Created June 13, 2021 00:55
Generates the smallest set of blank panels needed to fill any possible hole size in a modular synth from 1 to N
void main(List<String> arguments) {
// n is the largest space we're trying to fill. So we want to find the
// smallest (fewest pieces and smallest total area) set of blanks that can be
// used to fill a hole of any size from 1 to n.
//
// We know we will never need a single blank larger than n, since it couldn't
// be used in any of the holes. So the basic process is to generate all
// multisets from 1 to n. From those we discard the sets whose combinations
// don't cover all holes up to n. Then we keep the smallest set. In practice,
void method(String? s) {
if (s == null) return;
print(s.length);
}
void main() {
method(null);
}
// Function parameter types are in a "contravariant position", so allowing this
// override would break soundness. Consider:
class Base {
final String Function(dynamic val) validator;
}
class Derived extends Base {
String Function(String val) validator;
}
@munificent
munificent / dump_map.c
Created July 27, 2019 20:04
Dump a PPM image of a Wren map's hash buckets
// Generates a PPM image showing the entries in a Wren Map.
//
// Each pixel represents an entry. It will be black if the entry is empty is
// empty. Otherwise, it will be some other color. The red and green channels
// represents how far the key in that entry is from where it would ideally be.
// In other words, how many collisions occurred before it could be inserted.
// Brighter colors are worse. In particular, brighter green colors are much
// worse.
//
// A good hashing function will lead to an image containing a random-looking
Here is the relevant part of the log, the error seems to occur when trying to format the directory 'dart_style':
[1528/1570] ACTION //utils/dartfmt:dartfmt(//build/toolchain/linux:clang_x64)
FAILED: gen/dartfmt.dart.snapshot
python ../../build/gn_run_binary.py compiled_action dart --deterministic --packages=/dart-sdk/sdk/.packages --snapshot=gen/dartfmt.dart.snapshot --snapshot-depfile=/dart-sdk/sdk/out/ReleaseX64/gen/dartfmt.dart.snapshot.d --snapshot-kind=app-jit /dart-sdk/sdk/third_party/pkg_tested/dart_style/bin/format.dart ../../third_party/pkg_tested/dart_style
Command failed: ./dart --deterministic --packages=/dart-sdk/sdk/.packages --snapshot=gen/dartfmt.dart.snapshot --snapshot-depfile=/dart-sdk/sdk/out/ReleaseX64/gen/dartfmt.dart.snapshot.d --snapshot-kind=app-jit /dart-sdk/sdk/third_party/pkg_tested/dart_style/bin/format.dart ../../third_party/pkg_tested/dart_style
output: Formatting directory ../../third_party/pkg_tested/dart_style:
After which it prints the file it could not format/ Full list
@munificent
munificent / required-signatures.txt
Created March 30, 2019 00:11
Histogram of the various parameter signatures and how they mix required and optional named parameters
--- Signatures (869 total) ---
88 ( 10.127%): -@@@@@@
81 ( 9.321%): @
73 ( 8.400%): @@
41 ( 4.718%): @-
37 ( 4.258%): -@
34 ( 3.913%): -@@
34 ( 3.913%): @@@
26 ( 2.992%): -@-
20 ( 2.301%): @@-