Skip to content

Instantly share code, notes, and snippets.

View szepeshazi's full-sized avatar

András Szepesházi szepeshazi

View GitHub Profile
@szepeshazi
szepeshazi / deferred_test.dart
Created February 14, 2018 16:08
Dart: Debounce execution of callback
import 'dart:async';
class PayloadWithCompleter<T, K> {
Completer<K> completer = new Completer<K>();
T payload;
PayloadWithCompleter(this.payload);
}
class DeferredCallback<T, K> {
@szepeshazi
szepeshazi / main.dart
Last active December 10, 2018 11:45
Mutating a const nested map
void main() {
const Map<String, dynamic> constNestedMap = {
"root": {
"child": "Bert",
}
};
Map<String, dynamic> modNestedMap = Map.from(constNestedMap);
print(modNestedMap["root"]["child"]);
modNestedMap["root"]["child"] = "Ernie";
alias.clog=log --pretty=format:"%C(yellow)%h %Cred%ad %Cblue%an%Cgreen%d %Creset%s" --date=short
@szepeshazi
szepeshazi / custom_config.lua
Created November 22, 2019 12:50
Cmder custom prompt
local function verbatim(s)
s = string.gsub(s, "%%", "%%%%")
return s
end
local function set_custom_prompt()
-- get_cwd() is differently encoded than the clink.prompt.value, so everything other than
-- pure ASCII will get garbled. So try to parse the current directory from the original prompt
-- and only if that doesn't work, use get_cwd() directly.
-- The matching relies on the default prompt which ends in X:\PATH\PATH>
@szepeshazi
szepeshazi / main.dart
Last active October 24, 2020 19:00
Nested declarative navigator
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
@szepeshazi
szepeshazi / main.dart
Last active October 24, 2020 18:56
Multi-level declarative navigation
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
final counter = StateProvider<int>((_) => 0);
void main() {
runApp(ProviderScope(child: MyApp()));
}
class MyApp extends StatelessWidget {
@szepeshazi
szepeshazi / main.dart
Last active August 23, 2022 15:26
Flutter riverpod concurrency example
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'dart:async' show Timer;
import 'dart:math' show Random;
class ExpensiveNotifier extends StateNotifier<int> {
final rnd = Random();
ExpensiveNotifier() : super(0);
Future<void> update(int updateCount) async {
@szepeshazi
szepeshazi / main.dart
Last active September 14, 2022 08:46
Riverpod example #1
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
final counter = StateProvider<int>((ref) => 0);
void main() {
runApp(ProviderScope(child: MyApp()));
}
class MyApp extends StatelessWidget {
@szepeshazi
szepeshazi / main.dart
Last active September 14, 2022 08:48
Riverpod example #2
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
final counter = StateProvider<int>((ref) => 0);
void main() {
runApp(ProviderScope(child: MyApp()));
}
class MyApp extends StatelessWidget {