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
PORT=$1 | |
PIDS=$(lsof -t -i:$PORT) | |
for i in ${PIDS[@]} | |
do | |
kill -9 $i | |
echo "PID $i on port $PORT killed" | |
done |
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
# git-tag-move.sh | |
TAG = $1 | |
COMMIT = $2 | |
git tag --force TAG COMMIT | |
git push --force --tags |
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
import Foundation | |
var input = [[Int]]() | |
while let line = readLine() { | |
input.append(line.components(separatedBy: [" "]).map { Int($0)! }) | |
} | |
print(input) |
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
extension Array { | |
subscript(circular index: Int) -> Element? { | |
var i = index | |
if i < 0 || isEmpty { | |
return nil | |
} else if i > count - 1 { | |
i = index % count | |
} | |
return self[i] | |
} |
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 convertValue(oldValue: CGFloat, oldMin: CGFloat, oldMax: CGFloat, newMin: CGFloat, newMax: CGFloat) -> CGFloat { | |
let oldRange = oldMax - oldMin | |
let newRange = newMax - newMin | |
return (((oldValue - oldMin) * newRange) / oldRange) + newMin | |
} |
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
// | |
// ABLLinkManager.swift | |
// | |
// Created by Cem Olcay on 5.03.2018. | |
// Copyright © 2018 cemolcay. All rights reserved. | |
// | |
import Foundation | |
import AVFoundation |
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
import Foundation | |
func convert<T: FloatingPoint>(value: T, inRange: ClosedRange<T>, toRange: ClosedRange<T>) -> T { | |
let oldRange = inRange.upperBound - inRange.lowerBound | |
let newRange = toRange.upperBound - toRange.lowerBound | |
return (((value - inRange.lowerBound) * newRange) / oldRange) + toRange.lowerBound | |
} | |
func convert<T: SignedInteger>(value: T, inRange: ClosedRange<T>, toRange: ClosedRange<T>) -> T { | |
let oldRange = inRange.upperBound - inRange.lowerBound |
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 timebaseInfo = mach_timebase_info_data_t() | |
init() { | |
mach_timebase_info(&timebaseInfo) | |
} | |
func machAbsoluteToSeconds(machAbsolute: UInt64 = mach_absolute_time()) -> Double { | |
let nanos = Double(machAbsolute * UInt64(timebaseInfo.numer)) / Double(timebaseInfo.denom) | |
return nanos / 1.0e9; | |
} |
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
import Foundation | |
extension Array { | |
/// An array subscript extension that returns the element from the positive or negative circular index. | |
public subscript(circular index: Int) -> Element? { | |
guard count > 0 else { return nil } | |
let mod = index % count | |
let offset = index >= 0 ? 0 : count | |
let idx = mod == 0 ? 0 : mod + offset | |
return self[idx] |
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
import UIKit | |
extension UIViewController { | |
var topMostChild: UIViewController? { | |
if let tab = self as? UITabBarController { | |
return tab.selectedViewController?.topMostChild | |
} else if let nav = self as? UINavigationController { | |
return nav.topViewController?.topMostChild | |
} else if let split = self as? UISplitViewController { | |
return split.viewControllers.last?.topMostChild |