Skip to content

Instantly share code, notes, and snippets.

View rlaguilar's full-sized avatar

Reynaldo Aguilar rlaguilar

  • Canva
  • Sydney, Australia
View GitHub Profile
@rlaguilar
rlaguilar / Buffer.swift
Last active October 3, 2024 03:31
Producer consumer pattern using Swift concurrency
import Foundation
actor Buffer<Element> {
private let emptySlots = Stream<Void>()
private let availableElements = Stream<Element>()
init(capacity: Int) {
for _ in 0 ..< capacity {
emptySlots.push(())
}
@rlaguilar
rlaguilar / dealloc-breakpoint.md
Created March 7, 2022 03:43 — forked from eneko/dealloc-breakpoint.md
Xcode UIViewController dealloc breakpoint

Xcode deinit breakpoint for UIViewController

This breakpoint provides an easy way to track view controller deinitialization (deallocation) in UIKit-based applications. This can help finding memory leaks caused by retain cycles preventing view controllers from being deinitialized when dismissed or popped.

From Cédric Luthi's tweet in 2017:

Useful Xcode breakpoint. When you dismiss a controller and you don’t hear the pop sound (or see the log), you probably have a retain cycle.

import Foundation
import CoreGraphics
/*
Usage:
Interpolate(.linear).between(x, and: y, progress: progress) // progress is 0 to 1
*/
@rlaguilar
rlaguilar / CIFilter+Extension.swift
Created May 8, 2019 16:04 — forked from Umity/CIFilter+Extension.swift
CIFilter+Extension.swift
//
// Created by はるふ on 2017/12/11.
// Copyright © 2017年 ha1f. All rights reserved.
//
import Foundation
import CoreImage
import AVFoundation
extension CIFilter {
import UIKit
final class PagingCollectionView: UICollectionView, UICollectionViewDelegate {
private weak var externalDelegate: UICollectionViewDelegate?
override var delegate: UICollectionViewDelegate? {
get { return externalDelegate }
set {
externalDelegate = newValue
let currentDelegate = super.delegate
#!/bin/bash
# This script automatically sets the version and short version string of
# an Xcode project from the Git repository containing the project.
#
# To use this script in Xcode, add the script's path to a "Run Script" build
# phase for your application target.
set -o errexit
set -o nounset
@rlaguilar
rlaguilar / InteractiveTransitionTableViewDeselection.m
Created December 21, 2017 22:55 — forked from smileyborg/InteractiveTransitionCollectionViewDeselection.m
Animate table view deselection alongside interactive transition on iOS 11
/*
In iOS 11, interactive view controller transitions no longer scrub by setting the layer speed to zero
and changing the timeOffset. As a result of this change, implicit animations that occur in places like
-viewWillAppear: (called during an interactive transition) no longer end up “caught in” the animation.
To get the same behavior for table view row deselection as before, you can either use UITableViewController
which implements this for you, or you can implement it manually by deselecting the row in an alongside
animation for the transition (set up in -viewWillAppear: using the transition coordinator).
Here is an example implementation which correctly handles some of the more subtle corner cases:
@rlaguilar
rlaguilar / Emoji.plist
Created November 30, 2017 17:46 — forked from 0xced/Emoji.json
Extract emoji by category using the EmojiFoundation framework
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Activity</key>
<array>
<string>⚽️</string>
<string>🏀</string>
<string>🏈</string>
<string>⚾️</string>
@rlaguilar
rlaguilar / gist:69ba25716b307d573c070e3cf7726ebc
Created October 4, 2017 17:02 — forked from rtrouton/gist:2ca6f001b3cecb5037825c7f9d2e422e
Xcode iOS simulator download URLs (as of Xcode 8.3.1)
iOS 10.2 Simulator: https://devimages-cdn.apple.com/downloads/xcode/simulators/com.apple.pkg.iPhoneSimulatorSDK10_2-10.2.1.1484185528.dmg
iOS 10.1 Simulator: https://devimages-cdn.apple.com/downloads/xcode/simulators/com.apple.pkg.iPhoneSimulatorSDK10_1-10.1.1.1476902849.dmg
iOS 10.0 Simulator: https://devimages-cdn.apple.com/downloads/xcode/simulators/com.apple.pkg.iPhoneSimulatorSDK10_0-10.0.1.1474488730.dmg
iOS 9.3 Simulator: https://devimages.apple.com.edgekey.net/downloads/xcode/simulators/com.apple.pkg.iPhoneSimulatorSDK9_3-9.3.1.1460411551.dmg
iOS 9.2 Simulator: https://devimages.apple.com.edgekey.net/downloads/xcode/simulators/com.apple.pkg.iPhoneSimulatorSDK9_2-9.2.1.1451951473.dmg
iOS 9.1 Simulator: https://devimages.apple.com.edgekey.net/downloads/xcode/simulators/com.apple.pkg.iPhoneSimulatorSDK9_1-9.1.1.1446593668.dmg
iOS 9.0 Simulator: https://devimages.apple.com.edgekey.net/downloads/xcode/simulators/com.apple.pkg.iPhoneSimulatorSDK9_0-9.0.1.1443554484.dmg
iOS 8.4 Simulator: https://devimages.a
@rlaguilar
rlaguilar / String+Email.swift
Created September 26, 2017 17:49 — forked from DaveWoodCom/String+Email.swift
Swift method to check for a valid email address (uses Apples data detector instead of a regex)
extension String {
func isValidEmail() -> Bool {
guard !self.lowercaseString.hasPrefix("mailto:") else { return false }
guard let emailDetector = try? NSDataDetector(types: NSTextCheckingType.Link.rawValue) else { return false }
let matches = emailDetector.matchesInString(self, options: NSMatchingOptions.Anchored, range: NSRange(location: 0, length: self.characters.count))
guard matches.count == 1 else { return false }
return matches[0].URL?.scheme == "mailto"
}
}