Skip to content

Instantly share code, notes, and snippets.

@JamesSedlacek
JamesSedlacek / View+OpenUrl.swift
Last active April 19, 2025 21:50
This file provides a safe way to open URLs in SwiftUI applications.
//
// View+OpenUrl.swift
//
// Created by James Sedlacek on 11/26/24.
//
/// This file provides a safe way to open URLs in SwiftUI applications.
/// It adds a view modifier that handles URL opening with user confirmation
/// and multiple opening options (browser, in-app, or copy to clipboard).
///
@trvswgnr
trvswgnr / compress_video
Last active February 5, 2025 20:37
portable shell script to compress videos with ffmpeg
#!/bin/sh
print_usage() {
echo "usage: compress_video <input_file>"
echo "supported formats: mp4, webm, mkv, mov, avi, flv"
}
get_extension() {
f="${1##*/}"
case "$f" in
class FPSCounter extends StatefulWidget {
const FPSCounter({super.key});
@override
State<FPSCounter> createState() => _FPSCounterState();
}
class _FPSCounterState extends State<FPSCounter> {
int fps = 0;
@isaacadariku
isaacadariku / color_util.dart
Created September 26, 2023 14:33
Snippet of the color changes in reflection.app guide cards
const double minLightness = 0.30;
const double maxLightness = 0.55;
const double lightnessRange = maxLightness - minLightness;
const int numberOfColors = 3;
/// The top card gradients logic
///
/// Generate a list of gradient colors based on the provided [originalColor].
/// This function generates three gradient colors by adjusting the lightness of the [originalColor].
List<Color> generateGradientColors(Color originalColor) {
@kekland
kekland / main.dart
Last active July 22, 2023 09:18
Precomputed layout extent for items in a long ListView
import 'dart:math';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@craiglabenz
craiglabenz / chat_message_render_box.dart
Last active April 10, 2025 10:34
Demonstrates a custom RenderObject that draws chat messages like WhatsApp, where the `sentAt` timestamp is tucked into the last line if it fits
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
@matanlurey
matanlurey / ephemeral.dart
Created November 27, 2022 04:41
Example of a short-lived value in Dart.
/// A short-lived [value] `T`, that conditionally is re-computed or re-fetched.
class Ephemeral<T> {
final Future<T> Function() _fetch;
final bool Function(T) _isExpired;
/// Returns [value] by invoking [fetch].
///
/// If [isExpired] returns `false` for a given value, the value is re-fetched.
///
/// ```
@matanlurey
matanlurey / ansi.dart
Created September 4, 2022 02:13
A simple example of using Dart's "enhanced" enums for ANSI escape sequences
/// ANSI escape sequence constants.
///
/// See also:
/// - <https://vt100.net/docs/vt100-ug/chapter3.html>.
/// - <https://www.lihaoyi.com/post/BuildyourownCommandLinewithANSIescapecodes.html>
library ansi;
/// Provides constants for 16-bit colors and styles using ANSI-escape sequences.
enum AnsiEscapes16Bit {
/// Resets all styled output after this escape sequence.
@lukepighetti
lukepighetti / Fastfile
Last active August 22, 2022 08:17
How I build and release Flutter side projects on iOS https://twitter.com/luke_pighetti/status/1530156415611969537
default_platform(:ios)
APPLE_ISSUER_ID = ENV["APPLE_ISSUER_ID"]
APPLE_KEY_CONTENT = ENV["APPLE_KEY_CONTENT"]
APPLE_KEY_ID = ENV["APPLE_KEY_ID"]
DEVELOPER_APP_ID = ENV["DEVELOPER_APP_ID"]
DEVELOPER_APP_IDENTIFIER = ENV["DEVELOPER_APP_IDENTIFIER"]
GIT_AUTHORIZATION = ENV["GIT_AUTHORIZATION"]
GITHUB_RUN_NUMBER = ENV["GITHUB_RUN_NUMBER"]
PROVISIONING_PROFILE_SPECIFIER = ENV["PROVISIONING_PROFILE_SPECIFIER"]
@matanlurey
matanlurey / indent.dart
Created May 15, 2022 01:30
A fairly simple way to enhance "StringBuffer" to make recursive indentation easier.
extension IdentableStringSink on StringSink {
/// Provides a delegating implementation of [StringSink] on [invoke].
///
/// ```
/// String example(String name, int age) {
/// final sink = StringBuffer();
/// sink
/// ..writeln('Identification')
/// ..indent(2, (sink) {
/// sink