Skip to content

Instantly share code, notes, and snippets.

View blaugold's full-sized avatar

Gabriel Terwesten blaugold

View GitHub Profile

Nutze ToStringHelper

Anstatt toString() zu überschreiben, benutze ToStringHelper:

class Person with ToStringHelper {
  Person(this.name, this.age);

  final String name;
 final int age;
extension WaitFailFast2<A, B> on (Future<A>, Future<B>) {
Future<(A, B)> get waitFailFast async {
final results = await Future.wait([$1, $2]);
return (results[0] as A, results[1] as B);
}
}
extension WaitFailFast3<A, B, C> on (Future<A>, Future<B>, Future<C>) {
Future<(A, B, C)> get waitFailFast async {
final results = await Future.wait([$1, $2, $3]);
@blaugold
blaugold / interned_bytes.dart
Last active October 19, 2023 08:57
interned_bytes.dart
import 'dart:convert';
import 'dart:typed_data';
import 'package:collection/collection.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:meta/meta.dart';
@immutable
class InternedBytes {
static final _internedInstances = <WeakReference<InternedBytes>>[];
flutter: INFO 14:06:50.564 + 0ms [connectivity] connection status wifi
flutter: INFO 14:06:51.262 + 698ms [sync] User is signed in: Nl7TkP9LlAgd3LrsyRtQ7voBAB52
flutter: INFO 14:06:51.340 + 77ms [analytics] couch_document_loaded (doc: game:Nl7TkP9LlAgd3LrsyRtQ7voBAB52)
flutter: INFO 14:06:51.341 + 0ms [storage] loaded document game:Nl7TkP9LlAgd3LrsyRtQ7voBAB52
flutter: INFO 14:06:51.595 + 254ms [analytics] test_segmentation (a_a: true, consent_decline: standard, ad_load_timing: standard, core_package_ui: modern, b_b: standard)
flutter: INFO 14:06:51.637 + 41ms [migration] migration 14 was already handled
flutter: INFO 14:06:51.864 + 227ms [rewards] Reward next update: null
flutter: INFO 14:06:51.982 + 117ms [core] Loading bundled puzzles...
flutter: INFO 14:06:52.151 + 168ms [daily] remaining dates (normal): [2023-10-01, 2023-10-02, 2023-10-03, 2023-10-04, 2023-10-05, 2023-10-06, 2023-10-07, 2023-10-08, 2023-10-09, 2023-10-10, 2023-10-11, 2023-10-12, 20
@blaugold
blaugold / typescript-firebase-database-rules.ts
Last active August 10, 2023 07:11
Firebase Database Rules with TypeScript
// Use the TypeScript compiler to check your database rules.
// You'll get the most out of type checking if you define a database schema
// through interfaces and use it both in the web client and with the database rules.
// The compiler will catch misspellings and structural errors.
// It won't check for completeness since all properties are optional.
// Only works with TypeScript 2.1 and up because of mapped types being used.
interface DatabaseRuleSet {
'.read'?: string | boolean
'.write'?: string | boolean

Installation

Packages:

  • cbl: Contains the Couchbase Lite API.
  • cbl_flutter: Initializes Couchbase Lite for Flutter.
  • cbl_dart: Initializes Couchbase Lite for Standalone Dart or Flutter unit tests.
  • cbl_flutter_ce: Selects the Community Edition for use with Flutter.
  • cbl_flutter_ee: Selects the Enterprise Edition for use with Flutter.
import 'package:fleet/fleet.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const App());
}
class App extends StatelessWidget {
const App({super.key});
import 'package:cbl_flutter/cbl_flutter.dart';
Future<void> main() async {
// If you're initializing Couchbase Lite in your `main` function
// make sure to initialize Flutter before Couchbase Lite.
WidgetsFlutterBinding.ensureInitialized();
// Now initialize Couchbase Lite.
await CouchbaseLiteFlutter.init();
dependencies:
cbl: ^1.0.0
cbl_flutter: ^1.0.0
# This dependency selects the Community Edition of Couchbase Lite.
# For the Enterprise Edition add `cbl_flutter_ee` instead.
cbl_flutter_ce: ^1.0.0
dev_dependencies:
# This dependency allows you to use Couchbase Lite in Flutter
# unit tests and not just in integration tests.
cbl_dart: ^1.0.0
// For this example, we'll put the database into a global variable.
late final AsyncDatabase database;
Future<void> openDatabase() async {
// The database name will be used as the part of the file name
// of the database.
database = await Database.openAsync('notes-app');
}