Skip to content

Instantly share code, notes, and snippets.

View mrh-is's full-sized avatar

Michael Helmbrecht mrh-is

View GitHub Profile
import Foundation
protocol ObjCConvertible {}
extension String: ObjCConvertible {}
extension Int: ObjCConvertible {}
extension Double: ObjCConvertible {}
extension Bool: ObjCConvertible {}
func objCMethod(_ dict: [String: AnyObject]) {
print(dict)
@mrh-is
mrh-is / StrongFunctionReference.swift
Created January 30, 2018 21:33
Function references are strong references in Swift
class BlockHolder {
let block: () -> Void
init(block: @escaping () -> Void) {
self.block = block
}
}
class Doer {
func doIt() {
print("done")
@mrh-is
mrh-is / SantaArrivalCalculator.swift
Created December 23, 2016 10:41
When will Santa be at my house?
extension Location {
func closestLocationOnPath(start: Location, end: Location) -> (location: Location, t: Double, distance: Double) {
let pathVector = (latitude: end.latitude - start.latitude, longitude: end.longitude - start.longitude)
var t = (self.latitude * pathVector.latitude - start.latitude * pathVector.latitude + self.longitude * pathVector.longitude - start.longitude * pathVector.longitude) / (pow(pathVector.latitude,2) + pow(pathVector.longitude,2))
t = min(max(t, 0), 1)
let closestLocation = Location(latitude: start.latitude + t * pathVector.latitude, longitude: start.longitude + t * pathVector.longitude)
return (location: closestLocation, t: t, distance: distance(to: closestLocation))
}
func distance(to other: Location) -> Double {

Contract Killer

The popular open-source contract for web designers and developers by Stuff & Nonsense

  • Originally published: 23/12/2008
  • Revised date: 17/01/2014
  • Original post

@mrh-is
mrh-is / update_xcode_plugins.sh
Created December 16, 2014 18:50
Update DVTPlugInCompatibilityUUIDs for installed plugins for all Xcode versions
#!/bin/sh
# Based on https://gist.github.com/neonichu/9487584
# Now automatically updates every plugin for every version of Xcode on your machine
PLIST_BUDDY=/usr/libexec/PlistBuddy
function add_compatibility() {
"$PLIST_BUDDY" -c "Add DVTPlugInCompatibilityUUIDs:10 string $2" \
"$1/Contents/Info.plist"
@mrh-is
mrh-is / RLMResultsIterationIssue.swift
Last active August 29, 2015 14:10
RLMResults iteration issue
class MyObject: RLMObject {
dynamic var property: Int = 0
}
// Create some data
let realm = RLMRealm.defaultRealm()
realm.beginWriteTransaction()
for i in 1...6 {
realm.addObject(MyObject())
}