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
//Encode params to be web friendly and return a string. Reference ->http://stackoverflow.com/a/27724627/6091482 | |
extension String { | |
/// Percent escapes values to be added to a URL query as specified in RFC 3986 | |
/// | |
/// This percent-escapes all characters besides the alphanumeric character set and "-", ".", "_", and "~". | |
/// | |
/// http://www.ietf.org/rfc/rfc3986.txt | |
/// |
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
//Protocal that copyable class should conform | |
protocol Copying { | |
init(original: Self) | |
} | |
//Concrete class extension | |
extension Copying { | |
func copy() -> Self { | |
return Self.init(original: self) | |
} |
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
/** | |
@brief Returns true if images have same meta. Width, Height, bit depth. | |
@discussion Assumes images are non null. | |
*/ | |
func doImagesHaveSameMeta(#image1:CGImage, #image2:CGImage) -> Bool { | |
if CGImageGetWidth(image1) != CGImageGetWidth(image2) { | |
return false | |
} | |
if CGImageGetHeight(image1) != CGImageGetHeight(image2) { |
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
class MIDISampler : NSObject { | |
var engine:AVAudioEngine! | |
var playerNode:AVAudioPlayerNode! | |
var mixer:AVAudioMixerNode! | |
var sampler:AVAudioUnitSampler! | |
override init() { | |
super.init() | |
initAudioEngine() | |
} |
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
#!/bin/bash | |
set -e | |
set -u | |
altool="$(dirname "$(xcode-select -p)")/Applications/Application Loader.app/Contents/Frameworks/ITunesSoftwareService.framework/Support/altool" | |
ipa="path/to/foo.ipa" | |
echo "Validating app..." | |
time "$altool" --validate-app --type ios --file "$ipa" --username "$ITC_USER" --password "$ITC_PASSWORD" |
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
// MARK: - KVO | |
var observedPaths: [String] = [] | |
// Usage - observeKVO(keyPath: #keyPath(camera.inputCamera.whiteBalanceMode)) | |
func observeKVO(keyPath: String) -> Bool { | |
if shouldObserveKVO { | |
if self.classForCoder.automaticallyNotifiesObservers(forKey: keyPath) { | |
observedPaths.append(keyPath) | |
addObserver(self, forKeyPath: keyPath, options: [.old, .new], context: 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
class SpinView: UIView { | |
private var animating: Bool = false | |
private func spin(with options: UIViewAnimationOptions) { | |
// this spin completes 360 degrees every 2 seconds | |
UIView.animate(withDuration: 0.5, delay: 0, options: options, animations: {() -> Void in | |
self.transform = self.transform.rotated(by: .pi / 2) | |
}, completion: {(_ finished: Bool) -> Void in | |
if finished { | |
if self.animating { |
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 imageByNormalizingOrientation() -> UIImage { | |
if imageOrientation == .up { | |
return self | |
} | |
UIGraphicsBeginImageContextWithOptions(size, false, scale) | |
draw(in: CGRect(origin: CGPoint.zero, size: size)) | |
let normalizedImage: UIImage? = UIGraphicsGetImageFromCurrentImageContext() | |
UIGraphicsEndImageContext() | |
return normalizedImage! | |
} |
NewerOlder