Skip to content

Instantly share code, notes, and snippets.

View SteveAlexander's full-sized avatar

Steve Alexander SteveAlexander

View GitHub Profile
@SteveAlexander
SteveAlexander / interrupt.dart
Last active March 18, 2021 11:52
interrupting in a zone
import 'dart:async';
void main(List<String> arguments) {
var stop = false;
final checkShouldStop = () {
if (stop) {
throw StopException();
}
};
runZoned(
@SteveAlexander
SteveAlexander / levels.dart
Created January 15, 2021 15:45
Levels of abstraction of computation in Dart — see http://worrydream.com/#!2/LadderOfAbstraction
String level0() {
return "asd";
}
Future<String> level1Async() async {
await Future.delayed(Duration(seconds: 1), () {});
return "asd";
}
Iterable<String> level1Iteration() sync* {
yield "a";
@SteveAlexander
SteveAlexander / weighted_shuffle.dart
Last active June 18, 2022 17:56
Weighted shuffle in Dart
import 'dart:math' show Random, pow;
List<T> weightedShuffle<T>(List<T> items, List<num> weights, [Random rng]) {
// See https://softwareengineering.stackexchange.com/questions/233541/how-to-implement-a-weighted-shuffle
// and http://utopia.duth.gr/~pefraimi/research/data/2007EncOfAlg.pdf
assert(items.length == weights.length);
if (rng == null) rng = Random();
final List<double> values = weights
.map<double>((weight) => -pow(rng.nextDouble(), 1 / weight))
.toList(growable: false);
@SteveAlexander
SteveAlexander / README.md
Created September 18, 2019 14:46 — forked from matangover/README.md
Easily open files from Python tracebacks in iTerm2 directly in your editor
  1. In iTerm2, go to Settings -> Profiles -> Advanced -> Smart Selection -> Edit
  2. Click + to add a rule with the following values:
    • Notes: Python traceback
    • Regular Expression: File "(.+)", line ([0-9]+), in .+
    • Precision: Very High
  3. Click Edit Actions... and add an action to open in your editor. For example, if you use VS Code, add an action with the following values:
    • Title: Open in VS Code
    • Action: Run Command...
  • Parameter: /usr/local/bin/code -r -g "\1":\2
This file has been truncated, but you can view the full file.
$ flutter run --verbose
[ +34 ms] [/Users/steve/code/flutter/] git rev-parse --abbrev-ref --symbolic @{u}
[ +40 ms] Exit code 0 from: git rev-parse --abbrev-ref --symbolic @{u}
[ ] origin/dev
[ ] [/Users/steve/code/flutter/] git rev-parse --abbrev-ref HEAD
[ +12 ms] Exit code 0 from: git rev-parse --abbrev-ref HEAD
[ ] dev
[ ] [/Users/steve/code/flutter/] git ls-remote --get-url origin
[ +11 ms] Exit code 0 from: git ls-remote --get-url origin
[ ] https://github.com/flutter/flutter.git
import 'package:flutter/material.dart';
void main() {
runApp(new MaterialApp(
home: new DefaultTabController(
length: 3,
child: new SafeArea(
child: new Scaffold(
bottomNavigationBar: new Container(
child: new TabBar(