View urldecode_query_parameters.swift
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) | |
View delay.swift
func delay(delay:Double, closure:()->()) { | |
dispatch_after( | |
dispatch_time( | |
DISPATCH_TIME_NOW, | |
Int64(delay * Double(NSEC_PER_SEC)) | |
), | |
dispatch_get_main_queue(), closure) | |
} |
View gist:06c7861dc1a2196fdac8
/** 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 | |
} |
View links_header_parser.swift
/** 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) |
View clean_phone_number.swift
let phoneNumber = "(408) 555-5270" | |
let cleanedPhoneNumber = phoneNumber.componentsSeparatedByCharactersInSet(NSCharacterSet.decimalDigitCharacterSet().invertedSet).reduce("", +) | |
// 4085555270 |
View gist:2410117298c22dc971e3
/** 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"); |
View hour_floor.swift
/** 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)) |
View tableModifications.swift
// | |
// TableModifications.swift | |
// mn_ios | |
// | |
// Created by Alex Bosworth on 4/8/15. | |
// Copyright (c) 2015 adylitica. All rights reserved. | |
// | |
import UIKit |
View find_in_collection.swift
// 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 | |
} |
View amazon-s3.js
/* | |
* 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