๐พ Archived View for circadian.gemlog.org โบ 2023-04-25-dabbling-in-dart.gmi captured on 2024-03-21 at 15:11:14. Gemini links have been rewritten to link to archived content
โฌ ๏ธ Previous capture (2024-02-05)
โก๏ธ Next capture (2024-05-10)
-=-=-=-=-=-=-
I work at a big tech company on a programming language called Dart.
So, naturally I use it for any hobby programming and will probably end up writing Dart code to interact with Gemini.
Dart is a modern object-oriented language thatโs easy to pick up; it looks like a simplified Java. Its big feature is that it runs everywhere: it compiles to javascript for the web, to native code for iOS and Android, and can run in JIT and native compiled modes on various desktop/server platforms.
Youโre most likely to encounter Dart in day to day life as the language behind Flutter, the multi-platform app framework. But itโs just as well suited to simple scripting. Here is my first Dart code for Gemini:
import 'dart:io'; /// Replaces typewriter quotes and double dashes in all `.gmi` files under /// the specified path with their nicer unicode equivalents. /// /// Usage: dart fix_typography.dart <root path> void main(List<String> arguments) { final gmis = Directory(arguments[0]) .listSync(recursive: true) .whereType<File>() .where((f) => f.path.endsWith('.gmi')); for (final gmi in gmis) { print('Fixing ${gmi.path}.'); final lines = gmi.readAsLinesSync(); var skip = false; for (var i = 0; i != lines.length; ++i) { var line = lines[i]; if (line.startsWith('```')) { skip = !skip; continue; } if (skip) continue; line = line.replaceAll("'", "โ"); line = line.replaceAll('--', 'โ'); line = line.replaceAllMapped(RegExp(r'"(\w)'), (m) => 'โ${m.group(1)}'); line = line.replaceAllMapped(RegExp(r'(\w)"'), (m) => '${m.group(1)}โ'); lines[i] = line; } gmi.writeAsStringSync(lines.join('\n')); } }
It processes all `gmi` files under a root, replacing typewriter quotes and double dashes with their nicer unicode equivalents.
More fun that preprocessing would be a Gemini server in Dart; of course, if I write one, Iโll share!
Dart: a client-optimized language for fast apps on any platform
Flutter: Build apps for any screen
So far today, 2024-03-21, no feedback has been received.
โโโ / \ i a | C a \ D n | irc \ / โโโ