Skip to content

Instantly share code, notes, and snippets.

@frankschlegel
frankschlegel / TipShim.swift
Last active September 4, 2023 07:51
Working with TipKit when still supporting iOS 16 and below
import TipKit
/// Small helper protocol for a tip that is available below iOS 17
/// so that we can pass tips around and have members storing tips
/// (as stored properties can't be marked with `@available`).
@available(iOS, obsoleted: 17, message: "Can be removed once we only support iOS 17+")
public protocol TipShim {
@available(iOS 17, *)
import ComposableArchitecture
import SwiftUI
public enum ControlledStore {}
extension ControlledStore {
public enum Command: Equatable {
case run
case pause
}
import SwiftUI
extension CGPoint {
static func *(lhs: Self, rhs: CGFloat) -> Self {
.init(x: lhs.x * rhs, y: lhs.y * rhs)
}
}
// Idea: https://www.framer.com/showcase/project/lo2Qka8jtPXrjzZaPZdB/
@krzysztofzablocki
krzysztofzablocki / debugDiffing.swift
Created August 18, 2021 18:28
Higher order reducer for TCA that enables better debugging
import ComposableArchitecture
import Difference
import Foundation
/// A container for storing action filters.
///
/// The logic behind having this rather than a normal closure is that it allows us to namespace and gather action filters together in a consistent manner.
/// - Note: You should be adding extensions in your modules and exposing common filters you might want to use to focus your debugging work, e.g.
/// ```swift
/// extension ActionFilter where Action == AppAction {
@jverkoey
jverkoey / UIFont+CustomizedDynamicType.m
Created April 14, 2021 01:07
Dynamic Type system fonts with custom point sizes, weight, and italics
static const CGFloat kFontWeightEpsilon = FLT_EPSILON;
@implementation UIFont (CustomizedDynamicType)
+ (nonnull UIFont *)preferredFontWithDefaultSize:(CGFloat)size
textStyle:(nonnull UIFontTextStyle)textStyle {
return [self preferredFontWithDefaultSize:size
textStyle:textStyle
fontWeight:UIFontWeightRegular
italic:NO];
@apptekstudios
apptekstudios / CustomPicker.swift
Last active May 28, 2021 02:35
A variation on the picker designed by Federico Zanetello in his blog post (https://fivestars.blog/swiftui/inspecting-views.html) that allows any type of content to be used
//
// CustomPicker.swift
//
// Created by T Brennan on 27/3/21.
//
import SwiftUI
struct ContentView: View {
@State private var selection: Int? = 0
@lukeredpath
lukeredpath / LICENSE
Last active April 7, 2021 14:13
Unwrapping embedded case values in TCA test store tests
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
@mcvarer
mcvarer / cuda-11.2_installation_on_Ubuntu-18.04
Last active March 12, 2024 02:29
CUDA 11.2 Installation on Ubuntu 18.04
#!/bin/bash
## This gist contains instructions about cuda v11.2 and cudnn 8.1 installation in Ubuntu 18.04 for PyTorch
#############################################################################################
##### forked by : https://gist.github.com/Mahedi-61/2a2f1579d4271717d421065168ce6a73 ########
#############################################################################################
### steps ####
# verify the system has a cuda-capable gpu
@BrentMifsud
BrentMifsud / Image+Data.swift
Last active March 14, 2024 16:19
SwiftUI Image from data
import Foundation
import SwiftUI
#if canImport(UIKit)
import UIKit
#elseif canImport(AppKit)
import AppKit
#endif
extension Image {
/// Initializes a SwiftUI `Image` from data.
@steipete
steipete / KeyCommand.swift
Last active January 2, 2024 13:26
Add Keyboard Shortcuts to SwiftUI on iOS 13 when using `UIHostingController`. Requires using KeyboardEnabledHostingController as hosting class) See https://steipete.com/posts/fixing-keyboardshortcut-in-swiftui/
//
// KeyCommand.swift
// Adds Keyboard Shortcuts to SwiftUI on iOS 13
// See https://steipete.com/posts/fixing-keyboardshortcut-in-swiftui/
// License: MIT
//
// Usage: (wrap view in `KeyboardEnabledHostingController`)
// Button(action: {
// print("Button Tapped!!")
// }) {