Skip to content

Instantly share code, notes, and snippets.

Morten Just mortenjust

Block or report user

Report or block mortenjust

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:8ab8eb3774a02ac27c7cefc0af5c5244
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)
View detect 12 or 24 hour.swift
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
}
}
@mortenjust
mortenjust / obb+.sh
Created Jan 22, 2016
install obb on all connected devices, requires adb+
View obb+.sh
#!/bin/bash
######################################################################
#
#
# Obb+
# fkhairzad@
#
# Usage:
#
View split file name and extension.sh
FILE_BASE=`echo "${TEMPFILE%.*}"` #file without extension
FILE_EXT="${TEMPFILE##*.}" #file extension
@mortenjust
mortenjust / remap.java
Created Jan 16, 2016
processing-like map()
View remap.java
static float rangeMap(float value, float low1, float low2, float high1, float high2){
return low2 + (value - low1) * (high2 - low2) / (high1 - low1);
}
View map value from one range to another.swift
func rangeMap(whereIs value:Double, low1:Double, low2:Double, high1:Double, high2:Double) -> Double {
return low2 + (value - low1) * (high2 - low2) / (high1 - low1)
}
View Convert UIColor to HSBA values.swift
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)
}
View format distance.swift
let formatter = MKDistanceFormatter()
formatter.unitStyle = .Abbreviated
let distanceString = formatter.stringFromDistance(distance)
View format address.swift
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 ?? ""
View reverse geocode.swift
// 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 = ""
You can’t perform that action at this time.