Skip to content

Instantly share code, notes, and snippets.

View lanserxt's full-sized avatar
🖥️
Developing a dream

Anton Gubarenko lanserxt

🖥️
Developing a dream
View GitHub Profile
@lanserxt
lanserxt / FizzBuzz.swift
Created June 21, 2018 12:09
FizzBuzz test
func fizzBuzz(number: Int) -> String {
if number % 3 == 0 && number % 5 == 0 {
return "Fizz Buzz"
} else {
if number % 3 == 0 {
return "Fizz"
} else {
if number % 5 == 0 {
return "Buzz"
} else {
@lanserxt
lanserxt / FizzBuzz2.swift
Created June 21, 2018 13:14
FizzBuzz Test v2 - Tuples
func fizzBuzz(number: Int) -> String {
switch (number % 3 == 0, number % 5 == 0) {
case (true, true):
return "Fizz Buzz"
case (true, false):
return "Fizz"
case (false, true):
return "Buzz"
default:
return String(number)
@IBOutlet weak var tableView: UITableView! {
didSet{
tableView.delegate = self
}
}
@lanserxt
lanserxt / LoopedPlayer.swift
Last active December 28, 2018 08:54
Loop playback with AVQueuePlayer
//: [Previous](@previous)
import UIKit
import PlaygroundSupport
import AVFoundation
import AVKit
let frame = CGRect(x: 0, y: 0, width: 400, height: 400)
final class LoopedVideoPlayerView: UIView {
@lanserxt
lanserxt / LoopedPlayerView.swift
Last active October 25, 2023 16:18
Loop playback with AVQueuePlayer and AVPlayerLooper
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)
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("/") {
@lanserxt
lanserxt / gist:691dcb8d08f50dd2de6cc564dd8f75ec
Created November 30, 2018 09:39
Mix audio for multiple videos
do {
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, mode: AVAudioSessionModeDefault, options: .mixWithOthers)
try AVAudioSession.sharedInstance().setActive(true)
} catch {
print(error)
}
class Fraction: ExpressibleByStringLiteral {
private(set) var n: Int
private(set) var d: Int
init(numerator: Int, denominator:Int) {
self.n = numerator
self.d = denominator
}
@lanserxt
lanserxt / CellBlurAnimator.swift
Last active December 28, 2018 12:54
Blur animator
fileprivate var propertyAnimator: UIViewPropertyAnimator!
fileprivate var blurEffectView: UIVisualEffectView!
fileprivate var backGradientView: UIView!
func addWorkoutBlur() {
if !UIAccessibilityIsReduceTransparencyEnabled() {
if blurEffectView != nil {
blurEffectView.removeFromSuperview()
}
if backGradientView != nil {
@lanserxt
lanserxt / UINavigationController+Class.swift
Created January 15, 2019 11:39
UINavigationController extension to pop to specific class
extension UINavigationController {
func popToLastViewControllerType<T>(_ typeOfVC: T.Type) {
if let vc = viewControllers.last(where: {$0 is T}) {
popToViewController(vc, animated: true)
}
}
func popToFirstViewControllerType<T>(_ typeOfVC: T.Type) {
if let vc = viewControllers.first(where: {$0 is T}) {
popToViewController(vc, animated: true)