This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let simulator = UIDevice.currentDevice().model.rangeOfString("Simulator") != nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func exponentialMovingAverage(currentAverage: Double, newValue: Double, smoothing: Double) -> Double { | |
return smoothing * newValue + (1 - smoothing) * currentAverage | |
} | |
// Usage: | |
// var a = 3 | |
// a = exponentialMovingAverage(a, 8, 0.5) | |
// Swift 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>IDECodeSnippetCompletionPrefix</key> | |
<string>dispatch_after</string> | |
<key>IDECodeSnippetCompletionScopes</key> | |
<array> | |
<string>CodeExpression</string> | |
</array> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(lldb) posinwindow 0x796a0e60 | |
(CGPoint) $58 = (x=711, y=205.5) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func log<T>(message: T, fileName: String = __FILE__, lineNumber: Int = __LINE__, args: CVarArgType...) { | |
let date = NSDate() | |
let processInfo = NSProcessInfo() | |
let appName = processInfo.processName | |
let combined = String(format: String(stringInterpolationSegment: message), arguments: args) | |
println("\(date) \(appName) [\(fileName.lastPathComponent):\(lineNumber)] \(combined)") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var applicationActivityIndicators = 0 | |
extension UIApplication { | |
func startActivityIndicator() { | |
applicationActivityIndicators++ | |
UIApplication.sharedApplication().networkActivityIndicatorVisible = true | |
} | |
func stopActivityIndicator() { | |
applicationActivityIndicators-- | |
if applicationActivityIndicators <= 0 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) { | |
// Load resources for iOS 6.1 or earlier | |
} else { | |
// Load resources for iOS 7 or later | |
} | |
// But only in XCode 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def wrap(angle): | |
while angle > 2 * pi: | |
angle -= 2 * pi | |
while angle < 0: | |
angle += 2 * pi | |
return angle | |
def magnetometer_readings_to_tilt_compensated_heading(bx, by, bz, phi, theta, declinationRadians=0): | |
""" Takes in raw magnetometer values, pitch and roll and turns it into a tilt-compensated heading value ranging from -pi to pi (everything in this function should be in radians). | |
The correct value for declinationRadians can be found online: http://magnetic-declination.com/countries.php note that this value is in radians, not in degrees. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// UIResponder+sendAction.h | |
// Berik Visschers | |
// | |
// Created by Berik Visschers on 2013-03-22. | |
// Copyright (c) 2013 Xaton. All rights reserved. | |
// | |
#import <UIKit/UIKit.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A factor of 0.5 means that every newValue will have a 50% impact on the average | |
// Usage: self.average = updateRunningAverage(self.average, newValue, 0.3); | |
#define updateRunningAverage(average, newValue, factor) (((newValue) * (factor)) + ((average) * (1.0 - (factor)))) |