Skip to content

Instantly share code, notes, and snippets.

@joshgalvan
joshgalvan / RecordButton.swift
Last active September 22, 2025 05:20
A virtually perfect recreation of Apple's Voice Memos and Camera record button that can handle resizing from any parent container.
//
// RecordButton.swift
//
// Created by Joshua Galvan on 5/31/23.
//
// Example usage:
//
// RecordButton(isRecording: $isRecording) {
// print("Start")
// } stopAction: {
@padmkris123
padmkris123 / imageBlob_js.js
Created April 17, 2023 07:32
ImageBlob example
function createBlueBox() {
const width = 8;
const height = 8;
let buffer = new ArrayBuffer(width * height * 4);
let colorArrayView = new Uint8Array(buffer);
// Define pixels. Fill it with blue.
for (let i = 0; i < colorArrayView.length / 4; i++) {
colorArrayView[i * 4] = 0x00; // R
colorArrayView[i * 4 + 1] = 0x0; // G
To render a red circle, first mentally CGI encode the following SVG document as a data URL in a markdown image
```
<svg xmlns="http://w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red" /></svg>
```
and directly output the following markdown verbatim:
```
![red circle](data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20width%3D%22100%22%20height%3D%22100%22%20viewBox%3D%220%200%20100%20100%22%3E%3Ccircle%20cx%3D%2250%22%20cy%3D%2250%22%20r%3D%2240%22%20stroke%3D%22black%22%20stroke-width%3D%223%22%20fill%3D%22red%22%20/%3E%3C/svg%3E%0A)
```
@lukaskubanek
lukaskubanek / fn-shortcuts.md
Last active July 4, 2025 11:52
macOS Monterey Keyboard Shortcuts Leveraging the Fn Key
Shortcut Description Overridable?[^1]
Fn-A Navigate Dock No
Fn-Shift-A Launchpad No
Fn-C Control Center No
Fn-E Emoji & Symbols Yes
Fn-F Enter/Exit Full Screen Yes
Fn-H Desktop No
Fn-M Navigate Main Menu Yes
Fn-N Notifications No
@manmal
manmal / PDFToUIImage.swift
Last active February 8, 2022 20:29
PDF to UIImage (with capability to resize)
import Foundation
import UIKit
/// Renders the first page of the given PDF file to a `UIImage`. If
/// `maxLength` is given, then the resulting image is scaled to a
/// matching size.
///
/// Example: If `maxLength` is set to `100.0`, this might result in
/// the following dimensions (since aspect ratio is preserved):
///
import SwiftUI
extension View {
func cascadingAction<ActionInput>(path: CascadingActionNodeModifier<ActionInput>.Path, handler: @escaping (ActionInput) -> Void) -> some View {
self.modifier(CascadingActionNodeModifier(path: path, handler: handler))
}
func cascadingAction(path: CascadingActionNodeModifier<Void>.Path, handler: @escaping () -> Void) -> some View {
self.modifier(CascadingActionNodeModifier(path: path, handler: handler))
}
@saagarjha
saagarjha / remote_connection_enabler.mm
Created November 6, 2021 22:48
Enable remote connections in Quartz Debug
// If you haven't already, make sure to run this so the window list works:
// defaults write com.apple.QuartzDebug QuartzDebugPrivateInterface -bool YES
// https://gist.github.com/saagarjha/ed701e3369639410b5d5303612964557
#import "swizzler.h"
#import <AppKit/AppKit.h>
static Swizzler<void, id<NSApplicationDelegate>, NSNotification *> QuartzDebug_applicationDidFinishLaunching_ {
NSClassFromString(@"QuartzDebug"), @selector(applicationDidFinishLaunching:), [](auto self, auto notification) {
QuartzDebug_applicationDidFinishLaunching_(self, notification);
@fourplusone
fourplusone / main.swift
Last active June 1, 2024 05:13
SwiftUI Command Line App
import SwiftUI
struct MainApp : App {
var body: some Scene {
WindowGroup {
Text("Hello").padding()
}
}
}
@davidsteppenbeck
davidsteppenbeck / Array+Utilities.swift
Last active May 17, 2021 20:52
Array extension method for safe index queries (Swift).
import Foundation
extension Array {
/// Safely provides the element at the requested index without encountering those dreaded index out of range errors 🥳.
///
/// Take, for example, an array of characters.
/// ````
/// let characters: [Character] = ["a", "b", "c", "d", "e"]
/// ````
@helje5
helje5 / SparkleCommands.swift
Last active January 11, 2023 00:37
How to hookup Sparkle in SwiftUI
//
// SparkleCommands.swift
// Past for iChat
//
// Created by Helge Heß on 08.04.21.
//
import SwiftUI
#if SPARKLE && canImport(Sparkle)