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
var query = [String: String]() | |
if let queryString = url.query { | |
for q in queryString.componentsSeparatedByString("&") { | |
let pair = q.componentsSeparatedByString("=") | |
let value = pair[1] | |
.stringByReplacingOccurrencesOfString("+", withString: " ") | |
.stringByReplacingPercentEscapesUsingEncoding(NSUTF8StringEncoding) | |
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 delay(delay:Double, closure:()->()) { | |
dispatch_after( | |
dispatch_time( | |
DISPATCH_TIME_NOW, | |
Int64(delay * Double(NSEC_PER_SEC)) | |
), | |
dispatch_get_main_queue(), closure) | |
} |
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
/** Determine if value is present in array | |
*/ | |
func contains<T: Equatable>(array: [T], element: T) -> Bool { | |
for elem in array { if elem == element { return true } } | |
return false | |
} |
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
/** Get formatted links from links header | |
*/ | |
func getLinksFromHeader(linksString: String?) -> [String: String] { | |
var res = [String: String]() | |
if linksString == nil { return res } | |
var err: NSError? | |
let relRegex = NSRegularExpression(pattern: "rel=\\\"?([^\\\"]+)\\\"?", options: .CaseInsensitive, error: &err) |
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
let phoneNumber = "(408) 555-5270" | |
let cleanedPhoneNumber = phoneNumber.componentsSeparatedByCharactersInSet(NSCharacterSet.decimalDigitCharacterSet().invertedSet).reduce("", +) | |
// 4085555270 |
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
/** Delay execution until status bar Network Activity is completed | |
{} | |
*/ | |
automation.afterNetworkActivityEnds = function(args, cbk) { | |
var statusBar = target.frontMostApp().statusBar(); | |
var predicate = "name beginswith 'Network'"; | |
while (statusBar.elements().firstWithPredicate(predicate).isValid()) { | |
UIALogger.logMessage("Waiting for network"); |
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
/** Strip minutes and seconds from a date | |
*/ | |
func hourFloorFromDate(date: NSDate) -> NSDate? { | |
let calendar: NSCalendar | |
if let c = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian) { calendar = c } else { return nil } | |
let units = NSCalendarUnit.CalendarUnitYear | .CalendarUnitMonth | .CalendarUnitDay | .CalendarUnitHour | |
return calendar.dateFromComponents(calendar.components(units, fromDate: date)) |
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
// | |
// TableModifications.swift | |
// mn_ios | |
// | |
// Created by Alex Bosworth on 4/8/15. | |
// Copyright (c) 2015 adylitica. All rights reserved. | |
// | |
import UIKit |
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
// Find the index of the first element found in a collection | |
func findInCollection<T: CollectionType where T.Generator.Element: Equatable>(collection: T, val: T.Generator.Element...) -> T.Index? { | |
for v in val { if let index = find(collection, v) { return index } } | |
return nil | |
} |
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
/* | |
* Alex Bosworth | |
* | |
* A straightforward S3 library | |
* | |
* USE: var s3 = new S3(AWS_KEY, AWS_SECRET, {defaultBucket : MY_BUCKET}); | |
* s3.put(KEY, DATA); | |
* s3.get(KEY).on('success', function(data) { console.log(data); }); | |
* (more operations: buckets, info, list) | |
* |
OlderNewer