Skip to content

Instantly share code, notes, and snippets.

Avatar

Amir Hardon amirh

View GitHub Profile
@amirh
amirh / generate_pushid.dart
Last active Sep 11, 2020
Dart port of Firebase push ID generator (origin: https://gist.github.com/mikelehen/3596a30bd69384624c11)
View generate_pushid.dart
import 'dart:math' as math;
const String _kPushChars = '-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz';
typedef String StringCallback();
StringCallback generatePushId = () {
int lastPushTime = 0;
final List<int> randomSuffix = new List<int>(12);
final math.Random random = new math.Random.secure();
View 2048_gesture_detector.dart
return new GestureDetector(
behavior: HitTestBehavior.opaque,
onHorizontalDragEnd: (DragEndDetails d) {
if (d.primaryVelocity > 0) {
GameRedux.dispatch(context, moveRight());
} else {
GameRedux.dispatch(context, moveLeft());
}
},
//...
View state_test.dart
test('move right', () {
BoardState state = new BoardState([
[0, 2, 0, 0],
[0, 2, 0, 2],
[8, 0, 4, 4],
[2, 2, 0, 2],
]);
expect(state.moveRight().tiles, [
[0, 0, 0, 2],
You can’t perform that action at this time.