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
exports.respond = function(req, res) { | |
var responders = []; | |
for (var i = 2, arg; arg = arguments[i]; i++) responders.push(arguments[i]); | |
var next = function() { | |
var responder = responders.shift(); | |
if (typeof(responder) != 'function') return; | |
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 request = require('request'), | |
ENDPOINT = 'https://www.googleapis.com/'; | |
exports.save = function(opt, cbk) { | |
var auth = 'Bearer ' + opt.access_token; | |
opt.mimeType = opt.mimeType || 'application/octet-stream'; | |
request.post({ |
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 params = _.extend({ | |
api_key: MIXPANEL_KEY, | |
expire: Math.ceil(Date.now() / 1000) + 5 * 60 | |
}, | |
args.params); | |
var toSign = Object.keys(params) | |
.sort() | |
.map(function(key) { return key + '=' + params[key]; }) | |
.join(''); |
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
import UIKit | |
import Security | |
let serviceIdentifier = "com.company" | |
let accessGroup = "com.company.app" | |
let kSecClassValue = kSecClass as NSString | |
let kSecAttrAccountValue = kSecAttrAccount as NSString | |
let kSecValueDataValue = kSecValueData as NSString | |
let kSecClassGenericPasswordValue = kSecClassGenericPassword as NSString |
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
// | |
// Geohash.swift | |
// mn_ios | |
// | |
// Created by Alex Bosworth on 11/26/14. | |
// Copyright (c) 2014 adylitica. All rights reserved. | |
// | |
import Foundation | |
import MapKit |
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 |