Skip to content

Instantly share code, notes, and snippets.

View guid-empty's full-sized avatar

guid-empty guid-empty

View GitHub Profile
@guid-empty
guid-empty / main.dart
Last active April 9, 2024 08:10
Template Processor
import 'package:models/src/models/participant_descriptor_model.dart';
import 'package:models/src/models/quiz_session_model.dart';
import 'package:models/src/models/quiz_session_result_item_model.dart';
import 'package:models/src/models/templates/context_variables.dart';
typedef LazyValueGetter = Object? Function();
class TemplatesProcessorService {
static const _variableExpression = r'(?<variable>\%\w*\%)';
static final _variableExpressionRegex = RegExp(_variableExpression);
@guid-empty
guid-empty / leetcode_max_distance.dart
Created September 6, 2023 20:02
Leetcode -> Maximize Distance to Closest Person
import 'dart:math';
///
/// https://leetcode.com/problems/maximize-distance-to-closest-person/description/
/// 849. Maximize Distance to Closest Person
///
/// You are given an array representing a row of seats where seats[i] = 1 represents a person sitting in the ith seat, and seats[i] = 0 represents that the ith seat is empty (0-indexed).
/// There is at least one empty seat, and at least one person sitting.
/// Alex wants to sit in the seat such that the distance between him and the closest person to him is maximized.
/// Return that maximum distance to the closest person.
@guid-empty
guid-empty / pubspec.yaml
Created June 20, 2023 12:35
На порку Мише
name: company_office
description: TeleQuiz Online Company office implementation
publish_to: 'none'
version: 1.0.0+1
environment:
sdk: '>=2.17.0 <3.0.0'
flutter: ">=3.7.0"
dependencies:
@guid-empty
guid-empty / main.dart
Last active December 1, 2023 11:04
Checking authorization data hash for Telegram Login widget or Redirecting by LoginUrl from inline button keyboard
/// see more details here
/// https://core.telegram.org/widgets/login#checking-authorization
import 'package:crypto/crypto.dart'; //. https://pub.dev/packages/crypto
static const String botToken =
'XXXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
bool checkTelegramRegistrationData({
required final String id,
@guid-empty
guid-empty / main.dart
Last active September 4, 2022 21:48
How to create chunks from Iterable using the collection package
import 'package:collection/collection.dart';
void main() async {
final notChunked = Iterable.generate(100);
final chunked = notChunked.slices(30);
chunked.forEach(print);
}
@guid-empty
guid-empty / main.dart
Last active March 26, 2022 23:24
Multiple navigators for nested navigation
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
const Color darkBlue = Color.fromARGB(255, 18, 32, 47);
final GlobalKey<NavigatorState> firstPageContextNavigationKey = GlobalKey();
final GlobalKey<NavigatorState> homePageContextNavigationKey = GlobalKey();
@guid-empty
guid-empty / logging_interceptor.dart
Created February 2, 2022 23:17 — forked from apgapg/logging_interceptor.dart
Logging interceptor for dio, flutter
import 'dart:async';
import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
/// [LoggingInterceptor] is used to print logs during network requests.
/// It's better to add [LoggingInterceptor] to the tail of the interceptor queue,
/// otherwise the changes made in the interceptor behind A will not be printed out.
/// This is because the execution of interceptors is in the order of addition.
class LoggingInterceptor extends Interceptor {
@guid-empty
guid-empty / main.dart
Created August 25, 2021 14:12
TransferableTypedData example
import 'dart:io';
import 'dart:isolate';
import 'dart:math';
import 'dart:typed_data';
void main(List<dynamic> args) async {
ReceivePort receivePort = ReceivePort();
stdout.writeln('Создадим новый Isolate и передадим аргумент в entry point');
final isolate = await Isolate.spawn(someSoHeavyAndLongTask, receivePort.sendPort);
@guid-empty
guid-empty / main.dart
Created June 1, 2021 09:05
Usage the Synchronized package and locking the async operations demo
import 'dart:async';
import 'package:synchronized/synchronized.dart';
///
/// without synchronized logout should be the same:
/// emitting 1
/// listening the step 1
/// listening the step 1
/// emitting 1
@guid-empty
guid-empty / main.dart
Created June 1, 2021 08:08
Listening the stream created by async* generator function
import 'dart:async';
void main() {
SyncService sync = SyncService();
final subscription1 = sync.startUpload()
..onDone(() {
print('done');
});
final subscription2 = sync.startUpload()