Skip to content

Instantly share code, notes, and snippets.

@minikin
minikin / zoomMapToFitAnnotations()
Last active October 26, 2018 16:59
Zooms out a MKMapView to enclose all annotations (inc. current location).Swift.
func zoomMapToFitAnnotations() {
var zoomRect : MKMapRect = MKMapRectNull
for annotation in mapView.annotations as! [MKAnnotation] {
var annotationPoint = MKMapPointForCoordinate(annotation.coordinate)
var pointRect = MKMapRectMake(annotationPoint.x, annotationPoint.y, 0, 0)
if MKMapRectIsNull(zoomRect) {
zoomRect = pointRect
} else {
zoomRect = MKMapRectUnion(zoomRect, pointRect)
}
@minikin
minikin / UIImageExtension.swift
Last active August 29, 2015 14:26
imageFromUrl
import UIKit
extension UIImageView {
public func imageFromUrl(urlString: String) {
if let url = NSURL(string: urlString) {
let request = NSURLRequest(URL: url)
NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue()) {
(response: NSURLResponse!, data: NSData!, error: NSError!) -> Void in
self.image = UIImage(data: data)
@minikin
minikin / benchmarkSwift.swift
Last active September 29, 2019 09:10
Benchmark Swift code execution
/*
The former will log out the time required for a given section of code, with the latter returning that as a float.
Read more : http://stackoverflow.com/questions/25006235/how-to-benchmark-swift-code-execution
*/
func printTimeElapsedWhenRunningCode(title:String, operation:()->()) {
let startTime = CFAbsoluteTimeGetCurrent()
operation()
@minikin
minikin / removeAllAnnotations()
Last active April 13, 2023 08:19
Remove all annotation from mapView [MapBox]
/// Remove all annotation from mapView (MapBox)
func removeAllAnnotations() {
guard let annotations = mapView.annotations else { return print("Annotations Error") }
if annotations.count != 0 {
for annotation in annotations {
mapView.removeAnnotation(annotation)
}
@minikin
minikin / mapbox.log
Created February 19, 2016 15:17
mapbox crash
libc++abi.dylib`__cxa_throw:
-> 0x255b0584 <+0>: push {r4, r5, r6, r7, lr}
0x255b0586 <+2>: add r7, sp, #0xc
0x255b0588 <+4>: str r8, [sp, #-4]!
0x255b058c <+8>: mov r8, r2
0x255b058e <+10>: mov r6, r1
0x255b0590 <+12>: mov r4, r0
0x255b0592 <+14>: bl 0x255b018c ; __cxa_get_globals
0x255b0596 <+18>: mov r5, r0
0x255b0598 <+20>: bl 0x255b0d44 ; std::get_unexpected()
@minikin
minikin / Singleton.swift
Last active March 20, 2016 15:14
Singleton in Swift
// Singleton in Swift
import Foundation
class Animal: NSObject {
static let sharedAnimal = Animal()
}
let cat = Animal.sharedAnimal
let dog = Animal.sharedAnimal
@minikin
minikin / LICENSE
Created April 7, 2016 16:19 — forked from chriseidhof/LICENSE
A tiny networking library
Copyright 2015 Chris Eidhof
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHE
@minikin
minikin / struct_vs_inheritance.swift
Created April 10, 2016 20:05 — forked from AliSoftware/struct_vs_inheritance.swift
Swift, Struct & Inheritance: How to balance the will of using Struct & Value Types and the need for Inheritance?
// #!Swift-1.1
import Foundation
// MARK: - (1) classes
// Solution 1:
// - Use classes instead of struct
// Issue: Violate the concept of moving model to the value layer
// http://realm.io/news/andy-matuschak-controlling-complexity/
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )

Is a useful one-liner which will give you the full directory name of the script no matter where it is being called from

These will work as long as the last component of the path used to find the script is not a symlink (directory links are OK). If you want to also resolve any links to the script itself, you need a multi-line solution:

SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
@minikin
minikin / xcode-build-bump.sh
Created September 7, 2016 09:46 — forked from sekati/xcode-build-bump.sh
Xcode Auto-increment Build & Version Numbers
# xcode-build-bump.sh
# @desc Auto-increment the build number every time the project is run.
# @usage
# 1. Select: your Target in Xcode
# 2. Select: Build Phases Tab
# 3. Select: Add Build Phase -> Add Run Script
# 4. Paste code below in to new "Run Script" section
# 5. Drag the "Run Script" below "Link Binaries With Libraries"
# 6. Insure that your starting build number is set to a whole integer and not a float (e.g. 1, not 1.0)