I wrote a toy parser combinator using Dart 3.
[Warning, the current Dart compiler crashes when running this!]
To enable inline classes, add these lines to your analysis_options.yaml
file:
enable-experiment:
- inline-class
import 'dart:math'; | |
final _r = Random(); | |
/// Rolls dice according to a dice formula that follows this EBNF grammar: | |
/// | |
/// formula = term {op term}. | |
/// op = "+" | "-". | |
/// term = dice | integer. | |
/// dice = integer "d" integer. |
There's something called server-sent events which is an alternative to using web sockets if you want to break free from the strict request-response scheme.
I want to explore this technology using Dart.
First, let's create the simplest webserver that could possibly work:
Future main(List arguments) async {
import 'dart:async'; | |
/// A reactive variable which will automatically rerun an effect if | |
/// changed after using it within an effect function run by [createEffect]. | |
class Signal<T> { | |
Signal(T initialValue) : _value = initialValue; | |
T call() { | |
final tracker = _Tracker.current; | |
if (tracker != null) _trackers.add(tracker); |
import 'dart:async'; | |
import 'dart:convert'; | |
import 'dart:io'; | |
import 'dart:math' show Random; | |
final _random = Random.secure(); | |
/// Returns a unique id of length 20, based on ~120 bits of randomness. | |
String uid() { | |
const digits = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; |
import 'dart:io'; | |
class DotEnv { | |
DotEnv(String path) | |
: _environment = Map.fromIterable( | |
File(path) | |
.readAsLinesSync() | |
.map((line) => line.trim()) | |
.where((line) => line.isNotEmpty && !line.startsWith('#')), | |
key: (line) => line.substring(0, line.indexOf('=')).trim(), |
Ich habe aus Versehen eine SQL-Datenbank geschrieben.
Sie ist nicht produktiv einsetzbar, zeigt aber das Prinzip.
Eine Datenbank verwaltet Tabellen, die Zeilen und Spalten haben. Konzentrieren wir uns im folgenden auf eine Tabelle, denn Relationen zwischen Tabellen unterstütze ich nicht.
Spalten könnten auf einen Datentyp beschränkt sein, das unterstütze ich aber nicht. Da ich alles im Hauptspeicher halte, kann bei mir in jeder Spalte jedes Objekt stecken. Gedanklich beschränke ich mich aber auf null
und Werte der Typen bool
, int
, double
, String
und DateTime
.
import Cocoa | |
import FlutterMacOS | |
class MainFlutterWindow: NSWindow, NSWindowDelegate { | |
override func awakeFromNib() { | |
let flutterViewController = FlutterViewController.init() | |
let windowFrame = self.frame | |
self.contentViewController = flutterViewController | |
self.setFrame(windowFrame, display: true) | |