Skip to content

Instantly share code, notes, and snippets.

View kwalrath's full-sized avatar

Kathy Walrath kwalrath

View GitHub Profile
@kwalrath
kwalrath / index.html
Last active December 29, 2022 08:42
pi-monte-carlo (web version)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>pi-monte-carlo</title>
<script type="application/dart" src="main.dart"></script>
</head>
@kwalrath
kwalrath / main.dart
Last active June 6, 2018 21:23
pi-monte-carlo
import 'dart:async';
import 'dart:math' show Random;
main() async {
print('Compute π using the Monte Carlo method.');
await for (var estimate in computePi().take(500)) {
print('π ≅ $estimate');
}
}
@kwalrath
kwalrath / main.dart
Last active September 20, 2018 16:52 — forked from chalin/main.dart
futures/async-await
// Copyright (c) 2013, 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 'dart:async';
Future<void> printDailyNewsDigest() async {
var newsDigest = await gatherNewsReports();
print(newsDigest);
}
@kwalrath
kwalrath / main.dart
Last active September 20, 2018 16:53 — forked from chalin/main.dart
futures/futures-api
// Copyright (c) 2013, 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 'dart:async';
Future<void> printDailyNewsDigest() {
final future = gatherNewsReports();
return future.then(print);
// You don't *have* to return the future here.
@kwalrath
kwalrath / main.dart
Created August 16, 2018 21:25 — forked from Sfshaza/main.dart
Java-to-Dart codelab: Using a try-catch statement
import 'dart:math';
abstract class Shape {
factory Shape(String type) {
if (type == 'circle') return Circle(2);
if (type == 'square') return Square(2);
// To trigger exception, don't implement a check for 'triangle'.
throw 'Can\'t create $type.';
}
num get area;
@kwalrath
kwalrath / main.dart
Created August 17, 2018 21:33
playing with async-await
import 'dart:async';
Future<void> f() async {
print('1: before await');
await null;
print('2: after await');
}
// 3: before f()
// 1: before await
@kwalrath
kwalrath / index.html
Last active August 30, 2018 18:14
webdev example
<h2>A Simple To-Do List</h2>
<p>Things to do:</p>
<ul id="todolist">
</ul>
@kwalrath
kwalrath / main.dart
Last active September 20, 2018 01:39
post-Bob futures/futures-api
// Copyright (c) 2013, 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 'dart:async';
Future<void> printDailyNewsDigest() {
final future = gatherNewsReports();
return future.then(print);
// You don't *have* to return the future here.
@kwalrath
kwalrath / main.dart
Last active September 20, 2018 01:38
post-Bob futures/async-await
// Copyright (c) 2013, 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 'dart:async';
Future<void> printDailyNewsDigest() async {
var newsDigest = await gatherNewsReports();
print(newsDigest);
}
@kwalrath
kwalrath / analysis_options.yaml
Last active February 1, 2019 22:23
implicit-casts: false still ignored
# Supported lint rules and documentation:
# http://dart-lang.github.io/linter/lints/
analyzer:
exclude: [build/**]
strong-mode:
implicit-casts: false
implicit-dynamic: false
linter: