This file contains hidden or 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
// | |
// FMBlurable.swift | |
// FMBlurable | |
// | |
// Created by SIMON_NON_ADMIN on 18/09/2015. | |
// Copyright © 2015 Simon Gladman. All rights reserved. | |
// | |
// Thanks to romainmenke (https://twitter.com/romainmenke) for hint on a larger sample... | |
import UIKit |
This file contains hidden or 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 printRoots(a: Double, b: Double, c: Double, showImaginaryRoots: Bool = false) { | |
let b2 = b * b | |
let disc = b2 - (4 * a * c) | |
let discSqrt = sqrt(fabs(disc)) | |
let isImage = disc < 0 | |
let result = b * b - 4.0 * a * c |
This file contains hidden or 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
#insert after all pods declaring (just put at the bottom of a file) | |
post_install do |installer| | |
installer.pods_project.targets.each do |target| | |
if target.name == 'POD_NAME_HERE' | |
target.build_configurations.each do |config| | |
config.build_settings['SWIFT_VERSION'] = '4.0' | |
end | |
end | |
end | |
end |
This file contains hidden or 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 piCalc(_ totalPoints: Int) -> Double { | |
var nPointsInside = 0 | |
for _ in 1...totalPoints { | |
let (x, y) = (drand48() * 2 - 1, drand48() * 2 - 1) | |
if x * x + y * y <= 1 { | |
nPointsInside += 1 | |
} | |
} | |
return 4.0 * Double(nPointsInside) / Double(totalPoints) | |
} |
This file contains hidden or 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
fileprivate var propertyAnimator: UIViewPropertyAnimator! | |
fileprivate var blurEffectView: UIVisualEffectView! | |
fileprivate var backGradientView: UIView! | |
func addWorkoutBlur() { | |
if !UIAccessibilityIsReduceTransparencyEnabled() { | |
if blurEffectView != nil { | |
blurEffectView.removeFromSuperview() | |
} | |
if backGradientView != nil { |
This file contains hidden or 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 Fraction: ExpressibleByStringLiteral { | |
private(set) var n: Int | |
private(set) var d: Int | |
init(numerator: Int, denominator:Int) { | |
self.n = numerator | |
self.d = denominator | |
} | |
This file contains hidden or 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
do { | |
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, mode: AVAudioSessionModeDefault, options: .mixWithOthers) | |
try AVAudioSession.sharedInstance().setActive(true) | |
} catch { | |
print(error) | |
} |
This file contains hidden or 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 stripUrlToValid(_ url: String) -> String { | |
var stripped = url.trimmingCharacters(in: .whitespacesAndNewlines) | |
if stripped.hasPrefix("https") { | |
stripped = stripped.replacingOccurrences(of: "https", with: "") | |
} | |
if stripped.hasPrefix("http") { | |
stripped = stripped.replacingOccurrences(of: "http", with: "") | |
} | |
while stripped.hasPrefix(":") || stripped.hasPrefix("/") { |
This file contains hidden or 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
final class LoopedVideoPlayerView: UIView { | |
fileprivate var videoURL: URL? | |
fileprivate var queuePlayer: AVQueuePlayer? | |
fileprivate var playerLayer: AVPlayerLayer? | |
fileprivate var playbackLooper: AVPlayerLooper? | |
func prepareVideo(_ videoURL: URL) { | |
let playerItem = AVPlayerItem(url: videoURL) |