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
munificent / hidden_forward.md
Last active Apr 30, 2019
The "hidden forwarders" pattern in Dart
View hidden_forward.md

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:

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/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 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
munificent / generate.c
Last active May 24, 2019
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 {
Foo({
Bar bar,
Baz baz,
}) : assert(bar != null),
super(baz);
}
@munificent
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
munificent / import_syntax.md
Last active Mar 29, 2018
Thoughts in a relative and logical import syntax for Wren
View import_syntax.md

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
munificent / boxes.md
Created Feb 19, 2018
Bin-packing-esque
View boxes.md

This is in response to: https://gist.github.com/derek-knox/2aee55a146276b0514581f36b36b3f54

Here's some thoughts:

1.

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:

@munificent
munificent / function_types4.dart
Created Oct 20, 2016
Using `return func(params)` syntax.
View function_types4.dart
// Uses in typedefs.
typedef CompilerInputProvider = Future/*<String | List<int>>*/ func(Uri);
typedef ReadStringFromUri = Future<String> func(Uri);
typedef CompilerOutputProvider = EventSink<String> func(String name, String extension);
typedef DiagnosticHandler =
void func(Uri, int begin, int end, String message, Diagnostic kind);
You can’t perform that action at this time.