Skip to content

Instantly share code, notes, and snippets.

View f3ath's full-sized avatar
🐴
If I had ever learnt, I should have been a great proficient.

Alexey f3ath

🐴
If I had ever learnt, I should have been a great proficient.
View GitHub Profile
# Birthday paradox simulation. https://en.wikipedia.org/wiki/Birthday_problem
from argparse import ArgumentParser
from random import randint
from typing import Set
from math import factorial
DAYS_IN_YEAR = 365
def main():
@f3ath
f3ath / wtf.dart
Created April 26, 2023 03:21
Dart RegExp character class and surrogate pairs CLI vs Web
void main() {
print(RegExp(r'a[^x]b', unicode: true).hasMatch('a\uD800\uDD01b')); // true in Web, false in CLI
}
@f3ath
f3ath / index.md
Last active June 26, 2020 10:43
Dart package release automation

Automating Dart package release in 3 steps

Everyone who maintains a Dart package has to maintain the changelog and release updates once in a while. It can become cumbersome to keep the pubspec version and the changelog in sync manually. These two small tools can make release process fun.

1. Install the tools

pub global activate change
pub global activate pubspec_version
@f3ath
f3ath / main.dart
Last active February 14, 2020 07:19
MVC
abstract class State {}
abstract class Model {
Stream<State> get state;
void doThis();
void doThat();
}
class Controller {
final Model m;
Controller(this.m) {
@f3ath
f3ath / extenstion_on_typedef.dart
Created December 13, 2019 07:00
Dart extenston on typedef
extension Nullable<U, V> on _Fun<U, V> {
U nullable(V v) => v == null ? null : this(v);
}
typedef U _Fun<U, V>(V v);
[f3ath@glider json-api-dart]$ pub update
Resolving dependencies... (4.9s)
_fe_analyzer_shared 1.0.1
analyzer 0.39.2
args 1.5.2
async 2.4.0
boolean_selector 1.0.5
charcode 1.1.2
collection 1.14.12
convert 2.1.1
package f3ath.minesweeper;
import java.util.function.Function;
import java.util.stream.Stream;
public class Grid<T> implements Box {
private final int width;
private final int height;
private final T[][] grid;

After php 7 got released it became feasible to create long running apps at a relatively low price. Such tools like prooph, broadway, tactician, messenger, solving the most common challenges were made available at the engineers' disposal. But what if we dig a bit deeper.

We're going to tell a story of yet another attempt to reinvent the wheel, another tool to build a pub-sub app.

But first we take a quick glance over the today's major trends in the PHP world and scratch the surface of asynchronous programming.

PHP is meant to die

import 'dart:async';
import 'dart:convert';
import 'dart:io';
main() => stdin
.transform(utf8.decoder)
.transform(LineSplitter())
.asyncExpand(
(_) => Stream.fromFuture(Future.delayed(Duration(seconds: 1), () => _)))
.listen((_) => print("> $_"));
import 'dart:convert';
import 'dart:io';
import 'package:rxdart/rxdart.dart';
void main() => stdin
.transform(utf8.decoder)
.transform(LineSplitter())
.transform(IntervalStreamTransformer(Duration(seconds: 1)))
.listen((_) => print("> $_"));