๐Ÿ’พ Archived View for circadian.gemlog.org โ€บ 2023-04-25-dabbling-in-dart.gmi captured on 2024-07-08 at 23:18:25. Gemini links have been rewritten to link to archived content

View Raw

More Information

โฌ…๏ธ Previous capture (2024-06-16)

โžก๏ธ Next capture (2024-08-18)

๐Ÿšง View Differences

-=-=-=-=-=-=-

Dabbling in Dart

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!

Links

Dart: a client-optimized language for fast apps on any platform

Flutter: Build apps for any screen

Feedback ๐Ÿ“ฎ

๐Ÿ‘ Thanks!

๐Ÿ‘Ž Not for me.

๐Ÿคท No opinion.

Comments.

So far today, 2024-07-09, no feedback has been received.

   โ€”โ€”โ€”
 /     \   i a
| C   a \ D   n |
   irc   \     /
           โ€”โ€”โ€”