Skip to content

Instantly share code, notes, and snippets.

Bob Nystrom munificent

Block or report user

Report or block munificent

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
munificent / dump_map.c
Created Jul 27, 2019
Dump a PPM image of a Wren map's hash buckets
View dump_map.c
// 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
munificent /
Last active Apr 30, 2019
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:


View gist:1233df76e793cdba4c56ded4d8d4cf1d
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/ 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 / required-signatures.txt
Created Mar 30, 2019
Histogram of the various parameter signatures and how they mix required and optional named parameters
View required-signatures.txt
--- 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%): @@-
View generate.c
#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 / generate.c
Last active Feb 10, 2020
A random dungeon generator that fits on a business card
View generate.c
#include <time.h> // Robert Nystrom
#include <stdio.h> // @munificentbob
#include <stdlib.h> // for Ginny
#define r return // 2008-2019
#define l(a, b, c, d) for (i y=a;y\
<b; y++) for (int x = c; x < d; x++)
typedef int i;const i H=40;const i W
=80;i m[40][80];i g(i x){r rand()%x;
}void cave(i s){i w=g(10)+5;i h=g(6)
+3;i t=g(W-w-2)+1;i u=g(H-h-2)+1;l(u
View fmt.dart
class Foo extends A {
Bar bar,
Baz baz,
}) : assert(bar != null),
munificent / covariance_wat.dart
Created Jul 12, 2018
Function-typed fields and covariant generics
View covariance_wat.dart
class Foo<T> {
Function(T) callback;
T field;
add(T thing) {
T local = thing;
munificent /
Last active Mar 29, 2018
Thoughts in a relative and logical import syntax for Wren

So we need some syntax to distinguish between a relative import and a logical import. I'm not sure which way to go, and I'd like some feedback (or possibly other alternate ideas I haven't considered).

My two favorites are:

// Use
use "relative/path"
import "logical/path"
munificent /
Created Feb 19, 2018

This is in response to:

Here's some thoughts:


As long as even distribution is a soft goal and not a hard constraint, and you've got that specific set of small box sizes, it seems pretty tractable. It would be harder if your box sizes were weird and large like 4x19, etc. But with 1x1 in there, you can always find some solution that fills the region even if it ends up using more 1x1 boxes than you want.

There are probably a number of algorithms that would work. With those specific box sizes, I might try:

You can’t perform that action at this time.