Skip to content

Instantly share code, notes, and snippets.

@amirh
amirh / mdlink.js
Created September 13, 2022 15:16
Bookmarklet for copying a markdown link for the current page to the clipboard.
@amirh
amirh / generate_pushid.dart
Last active August 5, 2023 15:48
Dart port of Firebase push ID generator (origin: https://gist.github.com/mikelehen/3596a30bd69384624c11)
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();
return new GestureDetector(
behavior: HitTestBehavior.opaque,
onHorizontalDragEnd: (DragEndDetails d) {
if (d.primaryVelocity > 0) {
GameRedux.dispatch(context, moveRight());
} else {
GameRedux.dispatch(context, moveLeft());
}
},
//...
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],