View logMilestone.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Log the current filename and function, with an optional extra message. Call this with no arguments to simply print the current file and function. Log messages will include an Emoji selected from a list in the function, based on the hash of the filename, to make it easier to see which file a message comes from. | |
/// - Parameter message: Optional message to include | |
/// - file: Don't use; Swift will fill in the file name | |
/// - function: Don't use, Swift will fill in the function name | |
/// - line: Don't use, Swift will fill in the line number | |
func logMilestone(_ message: String? = nil, file: String = #file, function: String = #function, line: Int = #line) -> Void { | |
#if DEBUG | |
// Feel free to change the list of Emojis, but don't make it shorter, because a longer list is better. | |
let logEmojis = ["😀","😎","😱","😈","👺","👽","👾","🤖","🎃","👍","👁","🧠","🎒","🧤","🐶","🐱","🐭","🐹","🦊","🐻","🐨","🐵","🦄","🦋","🌈","🔥","💥","⭐️","🍉","🥝","🌽","🍔","🍿","🎹","🎁","❤️","🧡","💛","💚","💙","💜","🔔"] | |
let logEmoji = logEmojis[abs( |
View SecCertificateWrapper.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct SecCertificateWrapper : Comparable { | |
var data:Data | |
var cert:SecCertificate | |
// Initialize with a data object from the "DeveloperCertificates" | |
// array (see WrapperImplementation.swift) | |
init(data:Data) { | |
self.cert = SecCertificateCreateWithData(nil, data as CFData)! | |
// Use this later for parsing the date details from the cert |
View profname.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# ----------------------------------------------------- | |
# Usage: profname.rb /path/to/profiles/directory | |
# If no arguments are passed in, the default provisioning profiles directory | |
# on macOS is used: ~/Library/MobileDevice/Provisioning Profiles | |
# | |
# Script expects a directory, not a single file. Use grep on the command | |
# line to locate specific details. | |
# ----------------------------------------------------- |
View Date+ISO8601.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ISO 8601 Extension for Swift to send dates to Ruby on Rails | |
extension Date { | |
init(dateString:String) { | |
self = Date.iso8601Formatter.date(from: dateString)! | |
} | |
static let iso8601Formatter: ISO8601DateFormatter = { | |
let formatter = ISO8601DateFormatter() | |
formatter.formatOptions = [.withFullDate, | |
.withTime, |
View NumericSortedStringArray.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Sequence where Iterator.Element == String { | |
var sortedByNumberAndString : [String] { | |
return self.sorted { (s1, s2) -> Bool in | |
return s1.compare(s2, options: .numeric) == .orderedAscending | |
} | |
} | |
} | |
let sorted = ["8 Bob", "7 Joe", "11 Jimmy", "9 Larry", "1 Kyle"].sortedByNumberAndString |
View Collections+Additions.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension RangeReplaceableCollectionType where Generator.Element : Equatable { | |
mutating func appendDistinct(object : Generator.Element) { | |
if !self.contains(object) { | |
self.append(object) | |
} | |
} | |
} | |
// A derivative solution using filter instead of contains | |
extension RangeReplaceableCollectionType where Generator.Element : Equatable { |
View ImagePicker.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ImagePicker encapsulates UIImagePickerViewController functioality providing a convenient | |
// closure interface for responding to user interactions | |
import UIKit | |
import MobileCoreServices | |
class ImagePicker : NSObject, UINavigationControllerDelegate, UIImagePickerControllerDelegate { | |
var didFinishPickingMediaWithInfo:((info:[String:AnyObject]) -> ())? | |
var didCancelPickingMedia:(() -> ())? | |
let imagePicker = UIImagePickerController() |
View String+Additions.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension String | |
{ | |
var length: Int { | |
get { | |
return self.characters.count | |
} | |
} | |
func contains(s: String) -> Bool { | |
return self.rangeOfString(s) != nil ? true : false |
View Implemenation.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func checkShouldDownloadFileAtLocation(urlString:String, completion:((shouldDownload:Bool) -> ())?) { | |
var request = NSMutableURLRequest(URL: NSURL(string: urlString)!) | |
request.HTTPMethod = "HEAD" | |
var session = NSURLSession.sharedSession() | |
var err: NSError? | |
var task = session.dataTaskWithRequest(request, completionHandler: { [weak self] data, response, error -> Void in | |
if let strongSelf = self { | |
var isModified = false |
View gist:32d8ba0b277ce9bb1618
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension NSManagedObject { | |
func safeSetValuesForKeys(dictionary:[NSObject:AnyObject]) { | |
let attributes: [NSObject:AnyObject] = self.entity.attributesByName | |
var finalValue : AnyObject? = nil | |
for (attribute, value) in attributes { | |
if let val : NSNull = value as? NSNull { | |
continue; | |
} |
NewerOlder