Skip to content

Instantly share code, notes, and snippets.

View munificent's full-sized avatar

Bob Nystrom munificent

View GitHub Profile
@munificent
munificent / generate.c
Last active March 18, 2024 08:31
A random dungeon generator that fits on a business card
#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
extension on () {
() call() { print(':)'); return (); }
}
main() {
()()()()
()()()()()()
()() ()() ()()
()()()()()()()()
() ()()()() ()
@munificent
munificent / import_syntax.md
Last active October 24, 2023 18:46
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
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 / gist:6136198
Created August 1, 2013 23:15
For kicks, I scraped Github's language pages and sorted them by rank
#1 JavaScript
#2 Ruby
#3 Java
#4 Shell
#5 Python
#6 PHP
#7 C
#8 C++
#9 Perl
#10 CoffeeScript
#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 / 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 / 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 / gist:9749671
Last active June 23, 2022 04:04
You appear to be creating a new IDE...
You appear to be advocating a new:
[ ] cloud-hosted [ ] locally installable [ ] web-based [ ] browser-based [ ] language-agnostic
[ ] language-specific IDE. Your IDE will not succeed. Here is why it will not succeed.
You appear to believe that:
[ ] Syntax highlighting is what makes programming difficult
[ ] Garbage collection is free
[ ] Computers have infinite memory
[ ] Nobody really needs: