Skip to content

Instantly share code, notes, and snippets.

View munificent's full-sized avatar

Bob Nystrom munificent

View GitHub Profile
#include <stdio.h>
#include <stdlib.h>
const int H = 40;
const int W = 80;
char map[H][W];
int rnd(int max) {
return rand() % max;
@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%): @@-
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 / hidden_forward.md
Last active February 21, 2023 11:16
The "hidden forwarders" pattern in Dart

Say you have a package my_stuff. It contains two classes, A and B. You want to store them in separate files, but A needs access to some private functionality of B (in this case, the method _secret() and the constructor B._magic()). You don't want to expose that functionality outside of the package. You can express that like this:

The app using your package does:

some_app.dart:

@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
// 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;
}
void method(String? s) {
if (s == null) return;
print(s.length);
}
void main() {
method(null);
}
@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,
@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 = {}
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));