Skip to content

Instantly share code, notes, and snippets.

View munificent's full-sized avatar

Bob Nystrom munificent

View GitHub Profile
extension on () {
() call() { print(':)'); return (); }
}
main() {
()()()()
()()()()()()
()() ()() ()()
()()()()()()()()
() ()()()() ()
@munificent
munificent / wildcards.dart
Created February 1, 2023 00:44
Analyze a Dart corpus for uses of "_" as an identifier
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/token.dart';
import 'package:scrape/scrape.dart';
final wildcardPattern = RegExp(r'^_+$');
final typeNamePattern = RegExp(r'^_*[$A-Z]');
void main(List<String> arguments) {
Scrape()
..addHistogram('Declaration')
@munificent
munificent / parameter_numbers.dart
Created January 12, 2023 19:32
Scrapes Dart codebases to collect data on sequential numbered parameters and type parameters
import 'dart:collection';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:path/path.dart' as p;
import 'package:scrape/scrape.dart';
final _numberSuffix = RegExp(r'^([a-zA-Z_]+)([0-9]+)$');
final Map<String, Pkg> _packages = {};
@munificent
munificent / parameter_kinds.dart
Created February 17, 2022 22:55
Scrape script to look at what kinds of parameters are most common
// Copyright (c) 2020, 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('Signatures')
..addHistogram('Parameters')
@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);
}