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 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;
@PlugFox
PlugFox / screen_util.dart
Created June 14, 2023 12:37
Screen size util
import 'dart:ui' as ui;
import 'package:flutter/widgets.dart';
import 'package:meta/meta.dart';
/// {@macro screen_util}
extension ScreenUtilExtension on BuildContext {
/// Get current screen logical size representation
///
/// phone | <= 600 dp | 4 column
@PlugFox
PlugFox / main.dart
Created June 9, 2023 14:00
Translation ARB files with dart
import 'dart:async';
import 'dart:convert';
import 'dart:io' as io;
import 'package:args/args.dart';
/// Entry point for the application.
void main(List<String> arguments) => runZonedGuarded<void>(() async {
final argResult = (ArgParser()
..addFlag('help',
@PlugFox
PlugFox / example.dart
Last active April 23, 2024 13:40
Flutter Shimmer & Skeleton
void main() => runZonedGuarded<void>(
() => runApp(const App()),
(error, stackTrace) => log('Top level exception $error'),
);
class App extends StatelessWidget {
const App({super.key});
@override
Widget build(BuildContext context) => MaterialApp(
@PlugFox
PlugFox / dependencies.dart
Last active March 2, 2024 09:23
Log collector and application initialization with dependencies
/// Dependencies
abstract interface class Dependencies {
/// The state from the closest instance of this class.
factory Dependencies.of(BuildContext context) => InheritedDependencies.of(context);
/// Database
abstract final Database database;
}
final class $MutableDependencies implements Dependencies {