<commit_before>import Foundation
import UIKit

extension UIView {
    func layerGradient() {
        let layer : CAGradientLayer = CAGradientLayer()
        layer.frame.size = self.frame.size
        layer.frame.origin = CGPoint(x: 0, y: 0)
        
        let color1 = UIColor.white.withAlphaComponent(0.1).cgColor
        let color2 = UIColor.white.withAlphaComponent(1.0).cgColor
        
        layer.colors = [color1, color2]
        self.layer.insertSublayer(layer, at: 0)
    }
}

extension UIScrollView{
    
    func makeVisible(view: UIView, margin: CGFloat = 15, animated: Bool = false) {
        if view.superview == self{
            var frame = view.frame
            frame.size.height = frame.size.height + margin
            self.scrollRectToVisible(frame, animated: animated)
        }
    }
    
}

extension UIViewController{
    
    func showMessage(_ title: String, message:String, completion: (()->Void)? = nil){
        let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert)
        alert.addAction(UIAlertAction(title: "OK".localized, style: .default, handler: { (action: UIAlertAction!) in
            completion?()
        }))
        self.present(alert, animated: true, completion: nil)
    }
    
    func showDeleteAlert(_ title: String?, message:String?, completion: (()->Void)? = nil){
        let deleteAlert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert)
        deleteAlert.addAction(UIAlertAction(title: "Delete".localized, style: .destructive, handler: { (action: UIAlertAction!) in
            completion?()
        }))
        
        deleteAlert.addAction(UIAlertAction(title: "Cancel".localized, style: .cancel))
        present(deleteAlert, animated: true, completion: nil)
    }
    
    func showAlert(message:String){
        delayOnMainQueue {
            let alert = UIAlertController(title: "Alert".localized, message: message, preferredStyle: UIAlertControllerStyle.alert)
            alert.addAction(UIAlertAction(title: "OK".localized, style: UIAlertActionStyle.default, handler: nil))
            self.present(alert, animated: true, completion: nil)
        }    }
    
    func showError(message:String){
        delayOnMainQueue {
            let alert = UIAlertController(title: "Error".localized, message: message, preferredStyle: UIAlertControllerStyle.alert)
            alert.addAction(UIAlertAction(title: "OK".localized, style: UIAlertActionStyle.cancel))
            self.present(alert, animated: true, completion: nil)
        }    }
    
    func showError(error:Error){
        delayOnMainQueue {
            let alert = UIAlertController(title: "Error".localized, message: error.localizedDescription, preferredStyle: UIAlertControllerStyle.alert)
            alert.addAction(UIAlertAction(title: "OK".localized, style: UIAlertActionStyle.cancel))
            self.present(alert, animated: true, completion: nil)
        }
    }
    
    func showConnectionError(message:String){
        delayOnMainQueue {
            let messageConnection = "Please check your internet connection to continue".localized
            let alert = UIAlertController(title: "You are offline".localized, message: messageConnection, preferredStyle: UIAlertControllerStyle.alert)
            alert.addAction(UIAlertAction(title: "OK".localized, style: UIAlertActionStyle.cancel))
            self.present(alert, animated: true, completion: nil)
        }    }
    
}

extension UIImage {
    
    /// Returns a image that fills in newSize
    func resizedImage(newSize: CGSize) -> UIImage {<commit_msg>added alertStyle for iPhone and iPad<commit_after>import Foundation
import UIKit

extension UIView {
    func layerGradient() {
        let layer : CAGradientLayer = CAGradientLayer()
        layer.frame.size = self.frame.size
        layer.frame.origin = CGPoint(x: 0, y: 0)
        
        let color1 = UIColor.white.withAlphaComponent(0.1).cgColor
        let color2 = UIColor.white.withAlphaComponent(1.0).cgColor
        
        layer.colors = [color1, color2]
        self.layer.insertSublayer(layer, at: 0)
    }
}

extension UIScrollView{
    
    func makeVisible(view: UIView, margin: CGFloat = 15, animated: Bool = false) {
        if view.superview == self{
            var frame = view.frame
            frame.size.height = frame.size.height + margin
            self.scrollRectToVisible(frame, animated: animated)
        }
    }
    
}

extension UIViewController{
    
    func showMessage(_ title: String, message:String, completion: (()->Void)? = nil){
        let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert)
        alert.addAction(UIAlertAction(title: "OK".localized, style: .default, handler: { (action: UIAlertAction!) in
            completion?()
        }))
        self.present(alert, animated: true, completion: nil)
    }
    
    func showDeleteAlert(_ title: String?, message:String?, completion: (()->Void)? = nil){
        let deleteAlert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert)
        deleteAlert.addAction(UIAlertAction(title: "Delete".localized, style: .destructive, handler: { (action: UIAlertAction!) in
            completion?()
        }))
        
        deleteAlert.addAction(UIAlertAction(title: "Cancel".localized, style: .cancel))
        present(deleteAlert, animated: true, completion: nil)
    }
    
    func showAlert(message:String){
        delayOnMainQueue {
            let alert = UIAlertController(title: "Alert".localized, message: message, preferredStyle: UIAlertControllerStyle.alert)
            alert.addAction(UIAlertAction(title: "OK".localized, style: UIAlertActionStyle.default, handler: nil))
            self.present(alert, animated: true, completion: nil)
        }    }
    
    func showError(message:String){
        delayOnMainQueue {
            let alert = UIAlertController(title: "Error".localized, message: message, preferredStyle: UIAlertControllerStyle.alert)
            alert.addAction(UIAlertAction(title: "OK".localized, style: UIAlertActionStyle.cancel))
            self.present(alert, animated: true, completion: nil)
        }    }
    
    func showError(error:Error){
        delayOnMainQueue {
            let alert = UIAlertController(title: "Error".localized, message: error.localizedDescription, preferredStyle: UIAlertControllerStyle.alert)
            alert.addAction(UIAlertAction(title: "OK".localized, style: UIAlertActionStyle.cancel))
            self.present(alert, animated: true, completion: nil)
        }
    }
    
    func showConnectionError(message:String){
        delayOnMainQueue {
            let messageConnection = "Please check your internet connection to continue".localized
            let alert = UIAlertController(title: "You are offline".localized, message: messageConnection, preferredStyle: UIAlertControllerStyle.alert)
            alert.addAction(UIAlertAction(title: "OK".localized, style: UIAlertActionStyle.cancel))
            self.present(alert, animated: true, completion: nil)
        }    }
    
    var alertStyle: UIAlertControllerStyle{
        get{
            let style: UIAlertControllerStyle
            if(UIDevice.current.userInterfaceIdiom == .pad){
                style = .alert
            }else{
                style = .actionSheet
            }
            return style
        }
    }
}

extension UIImage {
    
    /// Returns a image that fills in newSize
    func resizedImage(newSize: CGSize) -> UIImage {
{'fraction_non_alphanumeric': 0.10182151749443061, 'fraction_numerical': 0.0034071550255536627, 'mean_word_length': 2.83710407239819, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3183052', 'n_tokens_mistral': 2074, 'n_tokens_neox': 2047, 'n_words': 473}