Skip to content

Instantly share code, notes, and snippets.

//
// OCXML.swift
// Created by Marco Arment on 9/23/24.
//
// Released into the public domain. Do whatever you'd like with this.
// No guarantees that it'll do anything, or do it correctly. Good luck!
//
import Foundation
@christianselig
christianselig / LongPressButton.swift
Last active November 4, 2024 06:52
How to accomplish a long-pressable button in SwiftUI with two different techniques. The first just uses SwiftUI but due to the simultaneous gesture requirement you also have to ensure both don't fire concurrently. The second uses UIKit and wraps UIButton and UILongPressGestureRecognizer which natively handles this behavior.
import SwiftUI
// PURE SwiftUI way with State tracking to prevent double events
struct ContentView: View {
@State private var ignoreTapEvent = false
var body: some View {
Button {
guard !ignoreTapEvent else {
@christianselig
christianselig / widget-center-async-await.swift
Created August 10, 2023 23:39
Adds async await support to WidgetCenter configuration fetch
import WidgetKit
extension WidgetCenter {
func currentConfigurations() async throws -> [WidgetInfo] {
try await withCheckedThrowingContinuation { continuation in
getCurrentConfigurations { result in
continuation.resume(with: result)
}
}
}
@chockenberry
chockenberry / simkill.sh
Last active December 9, 2023 14:04
A simple shell script to reset CoreSimulator
#!/bin/sh
pids=`ps axo pid,command | grep CoreSimulator | grep -v "grep CoreSimulator" | cut -c 1-5`
if [ "$1" = "go" ]; then
kill -9 $pids
elif [ "$1" = "echo" ]; then
echo $pids
else
pid_param=`echo $pids | tr -s ' ' ','`
@besser
besser / cura_klipper_end.gcode
Last active July 30, 2024 13:36
Klipper configuration file and Cura Start/End gcode
SET_GCODE_VARIABLE MACRO=END_PRINT VARIABLE=machine_depth VALUE={machine_depth}
END_PRINT