Skip to content

Instantly share code, notes, and snippets.

View Cosmo's full-sized avatar
📎
It looks like you're looking at my profile. Would you like help?

Devran Cosmo Uenal Cosmo

📎
It looks like you're looking at my profile. Would you like help?
View GitHub Profile
@artyom-stv
artyom-stv / gist:a87f572999074aa9afab03d8e96eef2e
Last active August 2, 2024 18:21
Visitor-based approach for accessing `@ViewBuilder`-provided content
// SwiftUI public API
public protocol View {
associatedtype Body: View
var body: Self.Body { get }
}
extension Never: View {
public typealias Body = Never
// The SwiftUI Lab
// Website: https://swiftui-lab.com
// Article: https://swiftui-lab.com/alignment-guides
import SwiftUI
class Model: ObservableObject {
@Published var minimumContainer = true
@Published var extendedTouchBar = false
@Published var twoPhases = true
@patriknyblad
patriknyblad / xcrun_simctl_cheatsheet.md
Last active September 10, 2025 15:53
iOS Simulator Terminal Commands `$ xcrun simctl`

Managing iOS Simulators

List all simulators created

$ xcrun simctl list --json

Delete old and unavailable simulators

$ xcrun simctl delete unavailable
class CircularBuffer<T> {
var bufferMaxSize: Int
var size = 0
var elements = Array<T?>(repeating: nil, count: 8)
var front: T? {
if isEmpty() {
return nil
} else {
@algal
algal / Zipping.swift
Created February 17, 2019 01:18
Zip files on iOS, without using external libraries and without interoperating with the low-level Compression framework
// Zipping.swift
// known-good: Swift 4.2
// Alexis Gallagher
import Foundation
public extension URL {
/// Creates a zip archive of the file or folder represented by this URL and returns a references to the zipped file
///
@Joony
Joony / SuperEllipse.swift
Created August 7, 2018 13:51
Create a super-ellipse, similar to Apple's app icons. Creates all the correct points so you can animate correctly between super-ellipses with different corners.
struct SuperEllipse {
static func superEllipse(forRect rect: CGRect, topRightCornerRadius trcr: CGFloat, bottomRightCornerRadius brcr: CGFloat, bottomLeftCornerRadius blcr: CGFloat, topLeftCornerRadius tlcr: CGFloat) -> UIBezierPath {
let trcr = 1.2 * trcr
let brcr = 1.2 * brcr
let blcr = 1.2 * blcr
let tlcr = 1.2 * tlcr
let path = UIBezierPath()
@ayamomiji
ayamomiji / list.html
Last active March 11, 2025 21:14
Stimulus example: smart scroll
<div data-controller="smart-scroll"
data-action="smart-scroll:added->smart-scroll#handleAdded
resize->smart-scroll#handleAdded
scroll->smart-scroll#handleScroll">
<div data-controller="smart-scroll-item">
aya: an an
</div>
<div data-controller="smart-scroll-item">
hatate: ni hao
</div>
@Marcocanc
Marcocanc / HomeKitQR.swift
Created January 3, 2018 09:38
Reverse engineering HomeKit QR Code decoding/encoding
import Foundation
func setupCodeFrom(uri: String) -> String {
let startIndex = uri.index(uri.startIndex, offsetBy: "X-HM://".count)
let endIndex = uri.index(uri.endIndex, offsetBy: -4)
var actualString = uri[startIndex..<endIndex]
let number = UInt(actualString, radix: 36)!
var code = String(format: "%08u", number & 0x7ffffff)
@smileyborg
smileyborg / InteractiveTransitionCollectionViewDeselection.m
Last active November 3, 2024 16:25
Animate table & collection view deselection alongside interactive transition (for iOS 11 and later)
// UICollectionView Objective-C example
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
NSIndexPath *selectedIndexPath = [[self.collectionView indexPathsForSelectedItems] firstObject];
if (selectedIndexPath != nil) {
id<UIViewControllerTransitionCoordinator> coordinator = self.transitionCoordinator;
if (coordinator != nil) {
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
@nathanfjohnson
nathanfjohnson / String+HTML.swift
Last active November 23, 2021 15:09 — forked from mwaterfall/StringExtensionHTML.swift
Decoding HTML Entities in Swift 4
// Swift 4
// Check out the history for contributions and acknowledgements.
extension String {
/// Returns a new string made by replacing all HTML character entity references with the corresponding character.
///
/// - Returns: decoded string
func decodingHTMLEntities() -> String {
var result = String()
var position = startIndex