Skip to content

Instantly share code, notes, and snippets.

View stucarney's full-sized avatar

Stu Carney stucarney

View GitHub Profile
@stucarney
stucarney / Storage.swift
Last active July 13, 2018 21:40 — forked from saoudrizwan/Storage.swift
[LINUX SUPPORTED] Helper class to easily store and retrieve Codable structs from/to disk. https://medium.com/@sdrzn/swift-4-codable-lets-make-things-even-easier-c793b6cf29e1
import Foundation
public class Storage {
fileprivate init() { }
/// Get the current working directory
/// - Returns: URL of current working directory
static func getCurrentDirectoryURL() -> URL {
return URL(fileURLWithPath: FileManager.default.currentDirectoryPath, isDirectory: true)
@stucarney
stucarney / FIRConnection.swift
Last active February 21, 2017 22:46
Firebase database connected? Swift class
var connectedRef: FIRDatabaseReference! {
return FIRDatabase.database().reference().child(".info/connected")
}
class FIRConnection {
static let sharedInstance = FIRConnection()
var handle: UInt?
var isConnected = false
@stucarney
stucarney / xcode_flag_todo_fixme.sh
Created January 18, 2017 18:35
Xcode / Swift - Run Script to highlight (warn) for any TODO: or FIXME: comments
TAGS="TODO:|FIXME:"
echo "searching ${SRCROOT} for ${TAGS}"
find "${SRCROOT}" \( -name "*.swift" \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($TAGS).*\$" | perl -p -e "s/($TAGS)/ warning: \$1/"
@stucarney
stucarney / xcode_set_build_num.rb
Last active January 18, 2017 18:33
XCode - Run Script to automatically set build # to git commit #
#!/usr/bin/ruby
# xcode-git-cfbundleversion.rb
# Update CFBundleVersion in Info.plist file with short Git revision string
# http://github.com/guicocoa/xcode-git-cfbundleversion/
#
# This is based on
# http://github.com/digdog/xcode-git-cfbundleversion/
# http://github.com/jsallis/xcode-git-versioner
# http://github.com/juretta/iphone-project-tools/tree/v1.0.3
@stucarney
stucarney / UIHelpers.swift
Last active November 14, 2020 15:30
iOS / Swift: Keyboard Show/Hide Animations for Views in a UIViewController
/**
Gathers all the data defined in `Keyboard Notification User Info Keys` from
a keyboard will/did show/hide `NSNotification` into an easier to use tuple.
- parameter notification: A notification resulting from a keyboard appearance notification,
e.g. `UIKeyboardWillShowNotification`
- returns: A tuple of data about the keyboard appearance extracted from the notification user info.
*/
public func keyboardInfoFromNotification(_ notification: Notification) -> (beginFrame: CGRect, endFrame: CGRect, animationCurve: UIViewAnimationOptions, animationDuration: Double) {
@stucarney
stucarney / TapToFocus.swift
Last active September 7, 2023 17:19
AVCaptureDevice - Tap-to-Focus feature (iOS)
@IBAction func handleTapToFocus(sender: UITapGestureRecognizer) {
if let device = captureDevice {
let focusPoint = sender.locationInView(previewView)
let focusScaledPointX = focusPoint.x / previewView.frame.size.width
let focusScaledPointY = focusPoint.y / previewView.frame.size.height
if device.isFocusModeSupported(.AutoFocus) && device.focusPointOfInterestSupported {
do {
try device.lockForConfiguration()
} catch {
print("ERROR: Could not lock camera device for configuration")