Skip to content

Instantly share code, notes, and snippets.

View matanlurey's full-sized avatar

Matan Lurey matanlurey

View GitHub Profile
import 'dart:async';
// Prints: "1", "4", "2", and "3".
main() {
print('1');
getInFuture2().then(print);
getInFuture3().then(print);
print('4');
}
import 'dart:async';
main() {
final completer = new Completer<String>();
completer.future.then(print);
completer.complete('Hello World');
}
import 'dart:async';
import 'dart:isolate';
/// Prints "6765" and again "6765".
main() async {
// Compute and print a fibonacci sequence synchronously.
print(syncFibonacci(20));
// Compute and print a fiboacci sequence on another thread (isolate).
print(await asyncFibonacci(20));
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'dart:isolate';
/// Prints {name: Joe User}, {name: Joe User}, and {name: Joe User}.
main() async {
// Reads and decodes a file synchronously.
print(readSync());
import 'dart:async';
import 'dart:convert';
import 'dart:io';
main() async {
final feed1 = getFeedSize();
if (feed1 is Future) {
print('From RPC: ${await feed1} bytes.');
}
final feed2 = getFeedSize();
@matanlurey
matanlurey / immutable_router_1.dart
Created April 26, 2017 17:26
An example of an immutable API for a SPA router, in Dart.
/// The 'Router' itself is just a stream of changes.
abstract class Router implements Stream<RouteChange> {}
/// An example of a route.
class Route {
final String path;
final Map<String, String> queryParameters;
const Route(this.path, {this.queryParameters: const {}});
}
@matanlurey
matanlurey / main.dart
Last active April 27, 2017 22:06 — forked from anonymous/main.dart
import 'dart:async';
main() {
final router = new Router();
router.listen(print);
router.route(const Route('/', query: const {'referredId': '1234'}));
router.route(const Route('/contact'));
}
/// A simple example of a 'Router' that is just a stream of [Route].
@matanlurey
matanlurey / main.dart
Last active April 27, 2017 22:06
An example of adding previous/next mechanics to the Router
import 'dart:async';
main() {
final router = new Router();
router.listen(print);
router.route(const Route('/', query: const {'referredId': '1234'}));
router.route(const Route('/contact'));
}
/// A simple example of a 'Router' that is just a stream of [Route].
@matanlurey
matanlurey / main.dart
Last active April 27, 2017 22:08
Yet another configurable router
import 'dart:async';
main() async {
final router1 = new Router();
print('--- Router 1 ---');
router1.listen(print);
router1.route(const Route('/', query: const {'referredId': '1234'}));
router1.route(const Route('/contact'));
await new Future((){});
class Animal {
void consume(Food food) {
System.out.println("Ate " + food.weight + " pounds of food!");
}
void consume(Water water) {
System.out.println("Drank " + water.amount + " liters of water!");
}
static void main(String[] args) {