Skip to content

Instantly share code, notes, and snippets.

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

Plague Fox PlugFox

🦊
🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊🦊
View GitHub Profile
@PlugFox
PlugFox / defer.dart
Created February 27, 2025 01:39
Go like defer in Dart
import 'dart:async' show Future, Zone, scheduleMicrotask;
final Object _deferredPushKey = Object();
/// Defers the given [callback] function to be executed after the current zone.
/// The callback will be executed in the reverse order of their registration.
void defer(void Function() callback) {
final push = Zone.current[_deferredPushKey];
if (push is void Function(void Function() callback)) {
push(callback);
@PlugFox
PlugFox / vixen_report.json
Created February 24, 2025 15:52
Vixen Report (initial)
{
"status": "ok",
"data": {
"from": "2025-02-17T15:51:19.647Z",
"to": "2025-02-24T15:51:19.647Z",
"active": [
{
"cid": -1001782660763,
"users": [
{
@PlugFox
PlugFox / main.dart
Created February 23, 2025 09:44
Date object
extension type const Date.of(DateTime _date) implements DateTime {
Date(int year, int month, int day) : _date = DateTime(year, month, day);
Date.now() : _date = DateTime.now();
Date.value(int value) : _date = DateTime((value >> 9), (value >> 5) & 0xF, value & 0x1F);
int get value => (_date.year << 9) | (_date.month << 5) | _date.day;
}
@PlugFox
PlugFox / main.dart
Last active February 18, 2025 12:22
Format numbers
// Format numbers
// https://dartpad.dev/?id=22aa280ffe2d847ca8c074b7eebca969
import 'dart:math' as math;
String formatNumber$1(int number) => number.toString().replaceAllMapped(
RegExp(r'(\d)(?=(\d{3})+(?!\d))'),
(match) => '${match[1]} ',
);
@PlugFox
PlugFox / nums.dart
Last active January 15, 2025 07:30
Dart: Nums benchmark
import 'dart:isolate';
import 'dart:math' as math;
import 'dart:typed_data';
import 'package:benchmark_harness/benchmark_harness.dart';
// $ dart run bin/nums.dart
//
// $ dart compile exe bin/nums.dart -o out/nums.exe
// $ ./out/nums.exe
@PlugFox
PlugFox / main.dart
Created January 13, 2025 21:59
Flutter chess example
import 'dart:math' as math;
import 'dart:ui';
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter/services.dart';
class _Binding = BindingBase
@PlugFox
PlugFox / game_painter_widget.dart
Last active December 1, 2024 07:10
Game painter widget
import 'package:flutter/rendering.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter/widgets.dart';
import 'package:vector_math/vector_math.dart';
/// Game interface.
abstract interface class IGameController {
/// Mount the game controller.
/// Called when the game controller is attached to the render box.
void mount(PipelineOwner owner, GamePainterRenderBox box);
@PlugFox
PlugFox / main.dart
Last active November 11, 2024 14:53
Mutex benchmark
/*
* Mutex benchmark
* https://gist.github.com/PlugFox/264d59a37d02dd06a7123ef19ee8537d
* https://dartpad.dev?id=264d59a37d02dd06a7123ef19ee8537d
* Mike Matiunin <[email protected]>, 11 November 2024
*/
import 'dart:async';
import 'dart:collection';
import 'dart:isolate';
@PlugFox
PlugFox / main.dart
Created November 7, 2024 17:55
Completer throws an error to the zone.
/*
* Completer throws an error to the zone.
* https://gist.github.com/PlugFox/675bdaf8ae604989e1dc7959abddbfd5
* https://dartpad.dev?id=675bdaf8ae604989e1dc7959abddbfd5
* Mike Matiunin <[email protected]>, 07 November 2024
*/
// ignore_for_file: cascade_invocations, avoid_print
import 'dart:async';
@PlugFox
PlugFox / main.dart
Last active October 25, 2024 19:46
Π‘ΠΎΡ€Ρ‚ΠΈΡ€ΠΎΠ²ΠΊΠ° чисСл ΠΎΡ‚ 10 Π΄ΠΎ 100 ΠΏΠΎ ΠΈΡ… русскому тСкстовому ΠΏΡ€Π΅Π΄ΡΡ‚Π°Π²Π»Π΅Π½ΠΈΡŽ
/*
* Π‘ΠΎΡ€Ρ‚ΠΈΡ€ΠΎΠ²ΠΊΠ° чисСл ΠΎΡ‚ 10 Π΄ΠΎ 100 ΠΏΠΎ ΠΈΡ… русскому тСкстовому ΠΏΡ€Π΅Π΄ΡΡ‚Π°Π²Π»Π΅Π½ΠΈΡŽ
* https://gist.github.com/PlugFox/cf41859c3c03fb8ee4ae1e8fd1de81f1
* https://dartpad.dev?id=cf41859c3c03fb8ee4ae1e8fd1de81f1
* Mike Matiunin <[email protected]>, 25 October 2024
*/
const units = [
'ноль',
'ΠΎΠ΄ΠΈΠ½',