Skip to content

Instantly share code, notes, and snippets.

View PlugFox's full-sized avatar
🦊
🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊

Plague Fox PlugFox

🦊
🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊
View GitHub Profile
@PlugFox
PlugFox / main.dart
Last active December 28, 2023 11:37
Long Polling example
/*
* Long Polling example
* https://gist.github.com/PlugFox/51038cb6f587332f6e803790a7d991e5
* https://dartpad.dev?id=51038cb6f587332f6e803790a7d991e5
* Matiunin Mikhail <plugfox@gmail.com>, 29 October 2023
*/
// ignore_for_file: avoid_print
import 'dart:async';
@PlugFox
PlugFox / main.dart
Last active October 29, 2023 20:09
Polling example
/*
* Polling example
* https://gist.github.com/PlugFox/b6e5bbbbfe79157c8229f1ba4808fbe9
* https://dartpad.dev?id=b6e5bbbbfe79157c8229f1ba4808fbe9
* Matiunin Mikhail <plugfox@gmail.com>, 29 October 2023
*/
// ignore_for_file: avoid_print
import 'dart:async';
@PlugFox
PlugFox / main.dart
Last active May 4, 2024 08:45
Пример обмена данными между клиентом и сервером по протоколу TCP/IP
/*
* Пример обмена данными между клиентом и сервером по протоколу TCP/IP
* https://gist.github.com/PlugFox/9cc2adb1d8df24fae2164e95dba6a911
* https://dartpad.dev?id=9cc2adb1d8df24fae2164e95dba6a911
* Matiunin Mikhail <plugfox@gmail.com>, 29 October 2023
*/
// ignore_for_file: avoid_print, lines_longer_than_80_chars
import 'dart:async';
@PlugFox
PlugFox / text_measure.dart
Last active October 19, 2023 07:31
Text measure widget
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
/// {@template text_measure}
/// TextMeasure widget.
/// {@endtemplate}
class TextMeasure extends StatefulWidget {
@PlugFox
PlugFox / main.dart
Last active September 18, 2023 16:56 — forked from kitsuniru/main.dart
'closure_1 as closure_2' problem
import 'dart:isolate';
void main() async {
final toMainIsolate = ReceivePort();
final stream = toMainIsolate;
void fn(ITargetAction action) => action.handleAction();
final worker = Worker<ITargetAction>(
port: toMainIsolate.sendPort,
@PlugFox
PlugFox / README.md
Last active September 15, 2023 18:05
CivetWeb vs Dart + Shelf vs Node.js vs C# Asp.Net.Core

Benchmark Results

Technology Time taken for tests (sec) Complete requests Failed requests Requests per second (mean) Time per request (ms) Time per request (concurrent ms) Transfer rate (Kbytes/sec)
CivetWeb 40.100 100,000 129 2493.77 400.999 0.401 136.21
Dart + Shelf 12.758 100,000 0 7837.96 127.584 0.128 2005.42
Node.js 10.457 100,000 0 9562.88 104.571 0.105 1055.28
@PlugFox
PlugFox / jwt.dart
Last active November 21, 2023 14:24
Centrifugo JWT
import 'dart:convert';
import 'package:crypto/crypto.dart';
import 'package:meta/meta.dart';
/// {@template jwt}
/// A JWT token consists of three parts: the header,
/// the payload, and the signature or encryption data.
/// The first two elements are JSON objects of a specific structure.
/// The third element is calculated based on the first two
@PlugFox
PlugFox / main.dart
Last active July 15, 2023 18:43
Json decode with cast
import 'dart:convert';
void main() {
final jsonRaw = '{"items": [1, 2, 3]}';
final json = jsonDecode(jsonRaw) as Map<String, Object?>; // good
try {
//final items = (json['items'] as List<Object?>).cast<int>().toList(); // good
final items = json['items'] as List<int>; // bad
print(items);
} on Object catch (err) {
@PlugFox
PlugFox / adaptive_widget.dart
Created June 20, 2023 07:52
Sizer and AdaptiveWidget
import 'package:flutter/widgets.dart';
import 'sizer.dart';
class AdaptiveWidget extends StatefulWidget {
const AdaptiveWidget({
required this.compactChild,
required this.extendedChild,
this.alignment = Alignment.center,
super.key,
});
/// Dependencies
abstract interface class Dependencies {
/// The state from the closest instance of this class.
factory Dependencies.of(BuildContext context) => InheritedDependencies.of(context);
/// App metadata
abstract final AppMetadata appMetadata;
/// Database
abstract final Database database;