Skip to content

Instantly share code, notes, and snippets.

View cmittendorf's full-sized avatar

Christian Mittendorf cmittendorf

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / RegisterSettingsBundleDefaults.swift
Created April 19, 2015 20:37
A small extension for registering NSUserDefaults default values using its registerDefaults method from the default values of a settings bundle. See http://oleb.net/blog/2014/02/nsuserdefaults-handling-default-values/ for more information on NSUserDefaults and default values. The code respects an ApplicationGroupContainerIdentifier key and uses N…
import Foundation
if let bundleURL = NSBundle.mainBundle().URLForResource("Settings", withExtension: "bundle") {
NSUserDefaults.registerDefaults(settingsBundleURL: bundleURL)
}
extension NSUserDefaults {
static func registerDefaults(#settingsBundleURL: NSURL) {
if let rootDict = NSDictionary(contentsOfURL: settingsBundleURL.URLByAppendingPathComponent("Root.plist")) {
var defaults: NSUserDefaults?
@cmittendorf
cmittendorf / trace_all_mysql_queries.d
Created February 26, 2015 18:11
A dtrace script for tracing all SQL queries a mysql server is executing. Call this script using `sudo ./trace_all_queries.d -p `pgrep mysqld`.
#!/usr/sbin/dtrace -s
#pragma D option quiet
pid$target:mysqld:*mysql_parse*:entry
{
printf("[%Y] %s\n", walltimestamp, copyinstr(arg1));
}
@cmittendorf
cmittendorf / rename_git_tags.rb
Created December 19, 2014 11:42
Renames already pushed git tags to follow a folder structure staging/<version> or master/<version>.
#!/usr/bin/env ruby
#
# renames git tags
# 3.7.0.31-staging -> staging/3.7.0.31
# 3.7.0 -> master/3.7.0
#
# see http://blog.sidmitra.com/how-to-rename-a-tag-already-pushed-to-a-remot
#
# make sure that other repo users call
# pull --prune --tags
@cmittendorf
cmittendorf / open_urls_in_string.rb
Last active August 29, 2015 14:09
A Ruby Automator action for opening all URLs and JIRA ticket ids from the input string.
require 'uri'
# without force_encoding ruby will throw an
# "invalid byte sequence in US-ASCII" exception
# when running this script from Automator
input = ARGF.read.force_encoding("UTF-8")
# scan for JIRA Ticket IDs like MYPROJECT-42
input.scan(/([A-Z]+\-[0-9]+)/).each do |id|
url = "https://<your JIRA server>/browse/#{id[0]}"
@cmittendorf
cmittendorf / ScriptProgressYosemite.js
Created October 26, 2014 09:44
If you want to use the new JavaScript for automation on Yosemite, you can display a scripts progress using a scripts Progress object.
Progress.totalUnitCount = 100
Progress.completedUnitCount = 0
Progress.description = "Testing progress"
Progress.additionalDescription = "foobar"
for(i = 0; i < Progress.totalUnitCount; i++) {
Progress.description = "Item " + i + " of " + Progress.totalUnitCount
delay(1)
Progress.completedUnitCount = i
}