Skip to content

Instantly share code, notes, and snippets.

View munificent's full-sized avatar

Bob Nystrom munificent

View GitHub Profile
@munificent
munificent / boxes.md
Created February 19, 2018 19:22
Bin-packing-esque

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 October 20, 2016 23:20
Using `return func(params)` syntax.
// 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);
@munificent
munificent / function_types3.dart
Created October 20, 2016 23:20
Using `return (params)` syntax
// Uses in typedefs.
typedef CompilerInputProvider = Future/*<String | List<int>>*/ (Uri);
typedef ReadStringFromUri = Future<String> (Uri);
typedef CompilerOutputProvider = EventSink<String> (String name, String extension);
typedef DiagnosticHandler =
void (Uri, int begin, int end, String message, Diagnostic kind);
@munificent
munificent / function_types2.dart
Last active October 20, 2016 23:20
Using `(params -> return)` syntax.
// Uses in typedefs.
typedef CompilerInputProvider = (Uri -> Future/*<String | List<int>>*/);
typedef ReadStringFromUri = (Uri -> Future<String>);
typedef CompilerOutputProvider = (String name, String extension -> EventSink<String>);
typedef DiagnosticHandler =
(Uri, int begin, int end, String message, Diagnostic kind -> void);
@munificent
munificent / function_types.dart
Last active October 20, 2016 23:20
Using `(params) -> return` syntax.
// Uses in typedefs.
typedef CompilerInputProvider = Uri->Future/*<String | List<int>>*/;
typedef ReadStringFromUri = Uri->Future<String>;
typedef CompilerOutputProvider = (String name, String extension) -> EventSink<String>;
typedef DiagnosticHandler =
(Uri, int begin, int end, String message, Diagnostic kind) -> void;
@munificent
munificent / randoms.wren
Created February 9, 2016 15:21
Given samplePick and sampleRes, which are the two random sampling algorithms, determines which is fastest for a given number of samples and collections
import "random" for Random
var TRIALS = 10
var RANDOM = Random.new()
class FindCutoffs {
// Determine the time ratio between picking and reservoir sampling [samples]
// from [list].
static calculateRatio(list, samples) {
System.gc()
@munificent
munificent / gist:12336bc4d9d1abee5bde
Created September 3, 2015 20:28
Pub test errors
~/dev/dart/sdk/third_party/pkg/pub ((1c08b84...)) → ../../../xcodebuild/ReleaseIA32/dart-sdk/bin/dart --package-root=../../../xcodebuild/ReleaseIA32/packages/ ../test/bin/test.dart --package-root=../../../xcodebuild/ReleaseIA32/packages/
00:22 +39 -1: test/build/copies_browser_js_next_to_entrypoints_test.dart: compiles dart.js and interop.js next to entrypoints
The schedule had 2 errors:
ScheduleError:
| Expected: match 'Got dependencies!|Changed \d+ dependenc(y|ies)!'
| Actual: 'Resolving dependencies...'
Stack chain:
| package:test/src/frontend/expect.dart 63:30 fail
| package:test/src/frontend/expect.dart 58:3 expect
@munificent
munificent / dev_compiler_output.js
Created August 5, 2015 16:33
Dart->JS output on a simple program
dart_library.library('simple', null, /* Imports */[
"dart_runtime/dart",
'dart/core'
], /* Lazy imports */[
], function(exports, dart, core) {
'use strict';
let dartx = dart.dartx;
class Simple extends core.Object {
Simple(name) {
this.name = name;
@munificent
munificent / dart2js.diff
Created June 9, 2015 22:50
This is a diff of the changes between formatting dart2js (151303 lines) using the current 0.1.8 version of the formatter and the new rules version.
diff --git a/pkg/compiler/lib/compiler.dart b/pkg/compiler/lib/compiler.dart
index cf68043..80a6c9c 100644
--- a/pkg/compiler/lib/compiler.dart
+++ b/pkg/compiler/lib/compiler.dart
@@ -96,7 +96,8 @@ class CompilationResult {
*/
Future<CompilationResult> compile(Uri script, Uri libraryRoot, Uri packageRoot,
CompilerInputProvider inputProvider, DiagnosticHandler handler,
- [List<String> options = const [], CompilerOutputProvider outputProvider,
+ [List<String> options = const [],
@munificent
munificent / lexer.wren
Created January 9, 2015 15:13
Start of lexer for Wren in Wren
class Token {
new(type, text) {
_type = type
_text = text
}
type { _type }
text { _text }
toString { _text + " " + _type }