Skip to content

Instantly share code, notes, and snippets.

Avatar
🦊
🦊🦊🦊🦊🦊

Plague Fox PlugFox

🦊
🦊🦊🦊🦊🦊
View GitHub Profile
@PlugFox
PlugFox / main.dart
Created Nov 29, 2021
Filter unicode symbols by code
View main.dart
/*
* Enum with extension
* https://gist.github.com/PlugFox/9c7bbfabcea80d41d380b4ee8ae4c75d
* https://dartpad.dev/9c7bbfabcea80d41d380b4ee8ae4c75d?id=&null_safety=true
*/
import 'dart:math' as math;
const String source = r'#51\J-!dv@dT_o6w^iж,7nдomzGpаWq0ЁKlGsH"~!UZHdпф5i3`N(';
@PlugFox
PlugFox / main.dart
Last active Nov 26, 2021
Date time parse and format as ISO-8601 with local timezone
View main.dart
/*
* Date time parse and format as ISO-8601 with local timezone
* https://gist.github.com/PlugFox/339bcd8dbec29a56fd53f8e0656e4a54
* https://dartpad.dev/339bcd8dbec29a56fd53f8e0656e4a54?id=&null_safety=true
*/
import 'dart:async';
import 'package:intl/intl.dart' as intl;
const String source = '2021-01-02T03:08:04+02:30';
@PlugFox
PlugFox / main.dart
Last active Nov 22, 2021
Enum with extension
View main.dart
/*
* Enum with extension
* https://gist.github.com/PlugFox/66b37ded0c086c4045143fd2732c099a
* https://dartpad.dev/66b37ded0c086c4045143fd2732c099a?id=&null_safety=true
*/
enum Country {
ru,
gb,
kz,
@PlugFox
PlugFox / hot_reload.dart
Created Nov 13, 2021 — forked from xvrh/hot_reload.dart
Shelf hot reload
View hot_reload.dart
import 'dart:io';
import 'dart:developer' as dev;
import 'package:shelf/shelf_io.dart' as io;
import 'package:shelf/shelf.dart' as shelf;
import 'package:vm_service/utils.dart';
import 'package:vm_service/vm_service.dart';
import 'package:vm_service/vm_service_io.dart';
import 'package:watcher/watcher.dart';
import 'package:stream_transform/stream_transform.dart';
@PlugFox
PlugFox / auto_update_column.sql
Last active Nov 13, 2021
Auto update column
View auto_update_column.sql
CREATE OR REPLACE FUNCTION jobs.trigger_update_timestamp()
RETURNS TRIGGER AS $$
BEGIN
NEW.updated = NOW()::timestamp;
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
-- DROP TABLE jobs.job;
@PlugFox
PlugFox / main.dart
Created Nov 12, 2021
Avoid `throw` in the block `on ... catch (e, st) { }`
View main.dart
/*
* Avoid `throw` in the block `on ... catch (e, st) { }`
* Instead `throw` you must use `Error.throwWithStackTrace`
* https://gist.github.com/PlugFox/1c955e7442f8a08e1cebee4d96177648
* https://dartpad.dev/1c955e7442f8a08e1cebee4d96177648?id=&null_safety=true
*/
void main() {
try {
repository();
@PlugFox
PlugFox / main.dart
Created Nov 11, 2021
No Tail Call Optimisation
View main.dart
/*
* No Tail Call Optimisation
* https://gist.github.com/PlugFox/9b11e06efd49529c99b7ff4ddf3660de
* https://dartpad.dev/9b11e06efd49529c99b7ff4ddf3660de?id=&null_safety=true
*/
void main() => fn(0);
int fn(int i) {
print(i++);
@PlugFox
PlugFox / main.dart
Last active Nov 10, 2021
ChunkWhile
View main.dart
/*
* Expando with method extension
* https://gist.github.com/PlugFox/cd8ba4736c95ada1ab2fe4d3ed220a33
* https://dartpad.dev/cd8ba4736c95ada1ab2fe4d3ed220a33?id=&null_safety=true
*/
void main() {
final list = <int>[1, 2, 4, 9, 10, 11, 12, 15, 16, 19, 20, 21];
print('chunkWhile:');
list.chunkWhile((a, b) => a + 1 == b).forEach(print);
@PlugFox
PlugFox / main.dart
Last active Nov 12, 2021
Runner for shelf server
View main.dart
void main(List<String> args) => l.capture(
() => runner<ServerConfig>(
initialization: () async {
final stopwatch = Stopwatch()..start();
// Установим маску
final ip = io.InternetAddress.anyIPv4;
// Получим http порт
@PlugFox
PlugFox / main.dart
Last active Nov 5, 2021
Split string to numbers
View main.dart
/*
* Split string to numbers
* https://gist.github.com/PlugFox/f4734be9b89f6b65534a7494ac622c49
* https://dartpad.dev/f4734be9b89f6b65534a7494ac622c49?id=&null_safety=true
*/
void main() => print('Моя дата: "2002-02-27T14:00:00-0500"!'.splitToNumbers(7));
extension SplitToNumbersX on String {
List<int> splitToNumbers([int max = 8]) => codeUnits