Skip to content

Instantly share code, notes, and snippets.

View cmittendorf's full-sized avatar

Christian Mittendorf cmittendorf

View GitHub Profile
@cmittendorf
cmittendorf / LocateMe.swift
Created April 23, 2015 07:32
A command line tool for Mac OS X written in Swift that uses CoreLocation for reverse geocoding a location from latitude and longitude. The geocoding part of this script will work on OS X as well as iOS.
#!/usr/bin/env swift
// Run this command line tool as a dynamic script or compile a binary
// using the following command:
// swiftc -sdk `xcrun --show-sdk-path` LocateMe.swift
import Cocoa
import CoreLocation
extension String {
@cmittendorf
cmittendorf / CreateNewBBEditDocumentFromTerminalContent.applescript
Last active August 29, 2015 14:22
This script creates a new document in BBEdit from the the content of your current Terminal window.
set content to missing value
display dialog ¬
"Which contents do you want to insert?" buttons {"Cancel", "Complete Buffer", "Currently visible content"} ¬
default button ¬
"Currently visible content" cancel button ¬
"Cancel" with title ¬
"Copy contents from Terminal.app" giving up after 10
if button returned of result is "Complete Buffer" then
@cmittendorf
cmittendorf / ExtractValuesFromAHashMap.groovy
Created June 26, 2015 11:36
An example for extracting values from a list of Maps
#!/usr/bin/env groovy
def m = [
nephew1:[name:"Huey", age:10],
nephew2:[name:"Dewey", age:12],
nephew3:[name:"Louie", age:13]
]
println m.collectEntries { [(it.key) : (it.value.name)] }
// [nephew1:Huey, nephew2:Dewey, nephew3:Louie]
@cmittendorf
cmittendorf / xcode-rebuild-ios-simulators-menu.rb
Last active August 29, 2015 14:24
From time to time, i.e. after installing Xcode beta versions, your devices menu is messed up and will show only a long list of identifiers and duplicates. This script will rebuild the iOS simulators menu by creating all possible combinations of devices and system versions.
#!/usr/bin/env ruby
device_types = []
runtimes = []
`xcrun simctl list`.each_line do |line|
device_type_id = /\((com\.apple\.CoreSimulator\.SimDeviceType\..*?)\)/.match(line)
if device_type_id then
device_types << device_type_id[1]
@cmittendorf
cmittendorf / DocumentIdentifier.swift
Created August 1, 2015 10:51
Returns the NSURLDocumentIdentifierKey for a file.
#!/usr/bin/env swift
import Foundation
let args = Process.arguments
if (args.count != 2) {
print("usage: \(args[0]) <file>\n")
exit(-1)
}
@cmittendorf
cmittendorf / StartTrackingDocumentIdentifier.swift
Created August 21, 2015 08:44
A script to enable tracking the DocumentIdentifier for a file on OSX.
#!/usr/bin/env swift
import Foundation
let args = Process.arguments
if (args.count != 2) {
print("usage: \(args[0].lastPathComponent) <file>\n")
exit(-1)
}
@cmittendorf
cmittendorf / sshToAWSServer.AppleScript
Last active September 17, 2015 22:16
An AppleScript to ssh with Terminal.app into the the currently selected server instance in the EC2 Management Console in Safari.app.
set aws to missing value
tell application "Safari"
tell current tab
set aws to do JavaScript "document.getElementsByClassName(\"AOB\")[0].textContent.match(/DNS: (.*\\.amazonaws\\.com)/)[1]"
end tell
end tell
if aws is not missing value then
tell application "Terminal"
@cmittendorf
cmittendorf / Open AWS Servers with SSH.applescript
Created November 11, 2015 10:27
Open all AWS EC2 instances of a specific server group using csshX from the current AWS console page in Safari.
set serversList to {}
set serverGroups to {"MyGroup1", "MyGroup2", "MyGroup3"}
set alertTitle to "Open AWS Servers with SSH"
on openServers(servers)
set csshx to "/usr/local/bin/csshX -y 4 --slave_settings_set CSSHX --ssh_args \"-oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null\" "
set saveTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {" "}
set command to (csshx & servers as text) & " &"
get do shell script command
@cmittendorf
cmittendorf / CGFloatToRadians.swift
Created June 12, 2016 08:19
Extend CGFloat to calculate the radians from its value.
extension CGFloat {
var radians: CGFloat {
let degree = Double(self)
return CGFloat(degree * M_PI / 180.0)
}
}
@cmittendorf
cmittendorf / Platform.swift
Created June 24, 2016 08:32
Test in your iOS app, if your app is running in the Simulator.
import Foundation
struct Platform {
/// Check if the current platform is the simulator.
///
/// - Returns: true if the current platform is the simulator
static let isSimulator: Bool = {
var isSim = false
#if arch(i386) || arch(x86_64)
isSim = true