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 task = Process() | |
var args = [String]() | |
args.append("-c") | |
let bundle = Bundle.main.bundlePath | |
args.append("sleep 0.2; open \"\(bundle)\"") | |
task.launchPath = "/bin/sh" | |
task.arguments = args | |
task.launch() | |
NSApplication.shared().terminate(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
func usesAMPM() -> Bool { | |
let locale = NSLocale.currentLocale() | |
let dateFormat = NSDateFormatter.dateFormatFromTemplate("j", options: 0, locale: locale)! | |
if dateFormat.rangeOfString("a") != nil { | |
return true | |
} | |
else { | |
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
#!/bin/bash | |
###################################################################### | |
# | |
# | |
# Obb+ | |
# fkhairzad@ | |
# | |
# Usage: | |
# |
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
FILE_BASE=`echo "${TEMPFILE%.*}"` #file without extension | |
FILE_EXT="${TEMPFILE##*.}" #file extension |
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
static float rangeMap(float value, float low1, float low2, float high1, float high2){ | |
return low2 + (value - low1) * (high2 - low2) / (high1 - low1); | |
} |
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 rangeMap(whereIs value:Double, low1:Double, low2:Double, high1:Double, high2:Double) -> Double { | |
return low2 + (value - low1) * (high2 - low2) / (high1 - low1) | |
} |
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 getHSBA(color:UIColor) -> (hue:CGFloat, saturation:CGFloat, brightness:CGFloat, alpha:CGFloat) { | |
var hue:CGFloat = 0.0 | |
var sat:CGFloat = 0.0 | |
var bri:CGFloat = 0.0 | |
var alpha:CGFloat = 0.0 | |
color.getHue(&hue, saturation: &sat, brightness: &bri, alpha: &alpha) | |
return (hue:hue, saturation:sat, brightness:bri, alpha:alpha) | |
} |
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 formatter = MKDistanceFormatter() | |
formatter.unitStyle = .Abbreviated | |
let distanceString = formatter.stringFromDistance(distance) |
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 Contacts | |
// Convert to the newer CNPostalAddress | |
func postalAddressFromAddressDictionary(addressdictionary: Dictionary<NSObject,AnyObject>) -> CNMutablePostalAddress { | |
let address = CNMutablePostalAddress() | |
address.street = addressdictionary["Street"] as? String ?? "" | |
address.state = addressdictionary["State"] as? String ?? "" | |
address.city = addressdictionary["City"] as? String ?? "" |
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
// https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLPlacemark_class/index.html#//apple_ref/occ/cl/CLPlacemark | |
CLGeocoder().reverseGeocodeLocation(location) { (placemarks, err) -> Void in | |
if let p = placemarks { | |
let address = p[0].name! | |
self.locationLabel.text = address | |
} else { | |
self.locationLabel.text = "" |