Skip to content

Instantly share code, notes, and snippets.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>Posts</title>
<script src="https://unpkg.com/htmx.org@1.4.1"></script>
<script src="https://unpkg.com/htmx.org@1.4.1/dist/ext/client-side-templates.js"></script>
<script src="https://unpkg.com/mustache@latest"></script>
</head>
@rodydavis
rodydavis / main.dart
Created July 2, 2024 19:47
Flutter Signals infinite scroll
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:signals/signals_flutter.dart';
void main() {
runApp(const App());
}
class App extends StatelessWidget {
@rodydavis
rodydavis / main.dart
Last active July 2, 2024 17:55
Flutter Counter with Signals
import 'package:flutter/material.dart';
import 'package:signals/signals_flutter.dart';
void main() {
runApp(const App());
}
class App extends StatelessWidget {
const App({super.key});
@rodydavis
rodydavis / pocketbase_id_generator.dart
Created June 10, 2024 00:06
ID Generator from the Go codebase
import 'dart:math';
const defaultIdLength = 15;
const defaultIdAlphabet = "abcdefghijklmnopqrstuvwxyz0123456789";
String pseudorandomStringWithAlphabet(int length, String alphabet) {
final List<int> b = List.filled(length, 0);
final int max = alphabet.length;
for (int i = 0; i < length; i++) {
@rodydavis
rodydavis / generator.dart
Last active May 29, 2024 21:21
Example of a possible Dart DSX (JSX like syntax) inspired by Templ in Go lang
import 'dart:io';
void main() {
final file = File('lib/hello.dsx');
final out = File('lib/hello.g.dart');
out.createSync();
out.writeAsStringSync(convert(file.readAsStringSync()));
}
String convert(String raw) {
@rodydavis
rodydavis / main.dart
Last active May 29, 2024 04:41
Gemini + Gemini
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:google_generative_ai/google_generative_ai.dart';
import 'package:url_launcher/link.dart';
final themeColor = ValueNotifier<Color>(Colors.orangeAccent);
int lastId = 0;
@rodydavis
rodydavis / main.dart
Last active May 7, 2024 18:25
Flutter AI Theme Generation (Function Calling)
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
@rodydavis
rodydavis / main.dart
Last active May 7, 2024 18:25
Gemini Tasks (Function Calling)
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
@rodydavis
rodydavis / dart_web_pick_file.dart
Created April 23, 2024 20:06
How to pick a file with package:web
Future<Uint8List?> pickFile() async {
final el = html.document.createElement('input') as html.HTMLInputElement;
el.type = 'file';
el.accept = 'image/*';
el.click();
final completer = Completer<Uri?>();
el.onchange = (html.Event e) {
final files = el.files;
if (files != null && files.length != 0) {
final file = files.item(0);
@rodydavis
rodydavis / main.dart
Last active May 7, 2024 18:25
Ask the Menu
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,