Skip to content

Instantly share code, notes, and snippets.

View ilikerobots's full-sized avatar

Mike Hoolehan ilikerobots

View GitHub Profile
FINE: Pub 1.15.0
MSG : Resolving dependencies...
SLVR: Solving dependencies:
| - angular2 2.0.0-beta.15 from hosted (angular2) (locked to 2.0.0-beta.15)
| - polymer 1.0.0-rc.16 from hosted (polymer) (locked to 1.0.0-rc.16)
SLVR: * start at root
SLVR: | angular2 2.0.0-beta.15 from hosted is locked
SLVR: | * select angular2 2.0.0-beta.15 from hosted
SLVR: | | * select pub itself
SLVR: | | | analyzer 0.27.1 from hosted is locked
@ilikerobots
ilikerobots / main.dart
Last active June 20, 2016 08:40
Basic examples of using Futures in Dart
import "dart:async";
import "dart:math" as math;
const asyncDelay = const Duration(seconds: 3);
///Asynchronous method that returns back a random int
Future<num> getNumber(num max) {
return new Future.delayed(asyncDelay, () => new math.Random().nextInt(max));
}
@ilikerobots
ilikerobots / main.dart
Last active June 20, 2016 12:58
Basic examples of using Stream methods in Dart
import "dart:async";
main() async {
print(" * Starting *");
Function elPrinter = (e) { print("Element $e");};
List<int> numbers = new List<int>.generate(10, (i) => i); // 0 - 9
Stream<int> numberStream = new Stream.fromIterable(numbers);
numberStream.map((x) => x * 10) //0,10,20,30...
.expand((x) => [x, x+1,x+2,x+3 ]) //0,1,2,3,10,11,12,13...
@ilikerobots
ilikerobots / main.dart
Last active June 20, 2016 13:01
Basic Examples: Mixins and typedefs in Dart
d(id) => new Document(id.toString()); //convenience function
List<Document> docs = [d('Foo'), d('bar'), d('BIZ'), d('Baz'), d('fab')];
///A simple document class with id
class Document {
String id;
Document(this.id);
toString() => id;
}
@ilikerobots
ilikerobots / main.dart
Last active June 21, 2022 10:45
Basic examples: Dart call() and Function.apply()
class Adder implements Function {
call(int a, int b) => a + b;
}
class Incrementer implements Function {
int _amt;
Incrementer(this._amt);
call(int a) => a + _amt;
}
@ilikerobots
ilikerobots / main.dart
Created June 21, 2016 06:36
Basic examples of ways to utilize async functions in Dart
import 'dart:async';
import 'dart:math' as math;
var rnd = new math.Random();
///Asynchronous method that returns back a random int
Future<int> getNumber(num max) {
return new Future.delayed(new Duration(seconds: rnd.nextInt(3)), () => rnd.nextInt(max));
}
import 'package:angular2/core.dart';
@Component(
selector: 'my-fields',
template: '<h2>Fields</h2>'
)
class FieldsComponent {
FieldsComponent();
}
import 'package:angular2/core.dart';
import 'package:angular2/router.dart';
import 'package:angular_dart_page_titles_on_route/page/fields_component.dart';
import 'package:angular_dart_page_titles_on_route/page/players_component.dart';
import 'package:angular_dart_page_titles_on_route/page/teams_component.dart';
@Component(
selector: 'my-app',
styleUrls: const ['app_component.css'],
templateUrl: 'app_component.html',
<nav>
<ul>
<li><a [routerLink]="['Players']">Players</a></li>
<li><a [routerLink]="['Teams']">Teams</a></li>
<li><a [routerLink]="['Fields']">Fields</a></li>
</ul>
</nav>
<div class="content" id="content">
<router-outlet></router-outlet>
import 'package:angular2/core.dart';
import 'package:angular2/router.dart';
@Component(
selector: 'my-player-detail',
template: '''<h2>Player Detail</h2> <h3>{{player}}</h3>''',
)
class PlayerDetailComponent implements OnInit {
final RouteParams _routeParams;
String player = "Not selected";