<commit_before>import CoreLocation
import Foundation
import UIKit

private extension UIColor {

    private func toHexString() -> String {

        var r: CGFloat = 0
        var g: CGFloat = 0
        var b: CGFloat = 0
        var a: CGFloat = 0

        self.getRed(&r, green: &g, blue: &b, alpha: &a)

        r *= 255
        g *= 255
        b *= 255

        return NSString(format: "%02x%02x%02x", Int(r), Int(g), Int(b))
    }

    private class func colorWithHexString(var hexString: String) -> UIColor {

        hexString = hexString.stringByReplacingOccurrencesOfString("#", withString: "")

        if (countElements(hexString) == 3) {
            hexString = "\(Array(hexString)[0])\(Array(hexString)[0])\(Array(hexString)[1])\(Array(hexString)[1])\(Array(hexString)[2])\(Array(hexString)[2])"
        }

        if (countElements(hexString) == 6) {
            var r: CGFloat = 0
            var g: CGFloat = 0
            var b: CGFloat = 0

            var hexInt: UInt32 = 0

            if (NSScanner(string: hexString).scanHexInt(&hexInt)) {
                r = CGFloat((hexInt >> 16) & 0xff) / 255
                g = CGFloat((hexInt >> 8) & 0xff) / 255
                b = CGFloat(hexInt & 0xff) / 255

                return UIColor(red: r, green: g, blue: b, alpha: 1)
            }
        }

        return UIColor.blackColor()
    }
}

public class MapboxStaticMap {

    private let requestURLStringBase = "https://api.tiles.mapbox.com/v4/"

    public enum ImageFormat: String {
        case PNG    = "png"
        case PNG256 = "png256"
        case PNG128 = "png128"
        case PNG64  = "png64"
        case PNG32  = "png32"
        case JPEG   = "jpg"
        case JPEG90 = "jpg90"
        case JPEG80 = "jpg80"
        case JPEG70 = "jpg70"
    }

    private(set) var requestURL: NSURL

    public lazy var image: UIImage? = {
        if let data = NSData(contentsOfURL: self.requestURL) {
            return UIImage(data: data)
        } else {
            return nil
        }
        }()

    public func imageWithCompletionHandler(handler: (UIImage? -> Void)) {
        let task = NSURLSession.sharedSession().dataTaskWithURL(requestURL, completionHandler: { (data: NSData!, response: NSURLResponse!, error: NSError!) in
            let image = UIImage(data: data)
            dispatch_async(dispatch_get_main_queue(), { Void -> Void in
                handler(image)
            })
        })
        task.resume()
    }

    init(mapID: String,
         center: CLLocationCoordinate2D = CLLocationCoordinate2D(latitude: 0, longitude: 0),
         zoom: Int = 0,
         size: CGSize,
         accessToken: String,
         format: ImageFormat = .PNG,
         retina: Bool = false,
         overlays: [Overlay] = [],
         autoFitFeatures: Bool = false) {

        var requestURLString = requestURLStringBase
        requestURLString += mapID
        requestURLString += "/"

        if (overlays.count > 0) {
            requestURLString += join(",", overlays.map({ return $0.requestString }))
            requestURLString += "/"
        }

        if (autoFitFeatures) {
            requestURLString += "auto/"
        } else {
            requestURLString += "\(center.longitude),\(center.latitude),\(zoom)/"
        }<commit_msg>clean up closure<commit_after>import CoreLocation
import Foundation
import UIKit

private extension UIColor {

    private func toHexString() -> String {

        var r: CGFloat = 0
        var g: CGFloat = 0
        var b: CGFloat = 0
        var a: CGFloat = 0

        self.getRed(&r, green: &g, blue: &b, alpha: &a)

        r *= 255
        g *= 255
        b *= 255

        return NSString(format: "%02x%02x%02x", Int(r), Int(g), Int(b))
    }

    private class func colorWithHexString(var hexString: String) -> UIColor {

        hexString = hexString.stringByReplacingOccurrencesOfString("#", withString: "")

        if (countElements(hexString) == 3) {
            hexString = "\(Array(hexString)[0])\(Array(hexString)[0])\(Array(hexString)[1])\(Array(hexString)[1])\(Array(hexString)[2])\(Array(hexString)[2])"
        }

        if (countElements(hexString) == 6) {
            var r: CGFloat = 0
            var g: CGFloat = 0
            var b: CGFloat = 0

            var hexInt: UInt32 = 0

            if (NSScanner(string: hexString).scanHexInt(&hexInt)) {
                r = CGFloat((hexInt >> 16) & 0xff) / 255
                g = CGFloat((hexInt >> 8) & 0xff) / 255
                b = CGFloat(hexInt & 0xff) / 255

                return UIColor(red: r, green: g, blue: b, alpha: 1)
            }
        }

        return UIColor.blackColor()
    }
}

public class MapboxStaticMap {

    private let requestURLStringBase = "https://api.tiles.mapbox.com/v4/"

    public enum ImageFormat: String {
        case PNG    = "png"
        case PNG256 = "png256"
        case PNG128 = "png128"
        case PNG64  = "png64"
        case PNG32  = "png32"
        case JPEG   = "jpg"
        case JPEG90 = "jpg90"
        case JPEG80 = "jpg80"
        case JPEG70 = "jpg70"
    }

    private(set) var requestURL: NSURL

    public lazy var image: UIImage? = {
        if let data = NSData(contentsOfURL: self.requestURL) {
            return UIImage(data: data)
        } else {
            return nil
        }
        }()

    public func imageWithCompletionHandler(handler: (UIImage? -> Void)) {
        let task = NSURLSession.sharedSession().dataTaskWithURL(requestURL, completionHandler: { (data: NSData!, response: NSURLResponse!, error: NSError!) in
            let image = UIImage(data: data)
            dispatch_async(dispatch_get_main_queue(), {
                handler(image)
            })
        })
        task.resume()
    }

    init(mapID: String,
         center: CLLocationCoordinate2D = CLLocationCoordinate2D(latitude: 0, longitude: 0),
         zoom: Int = 0,
         size: CGSize,
         accessToken: String,
         format: ImageFormat = .PNG,
         retina: Bool = false,
         overlays: [Overlay] = [],
         autoFitFeatures: Bool = false) {

        var requestURLString = requestURLStringBase
        requestURLString += mapID
        requestURLString += "/"

        if (overlays.count > 0) {
            requestURLString += join(",", overlays.map({ return $0.requestString }))
            requestURLString += "/"
        }

        if (autoFitFeatures) {
            requestURLString += "auto/"
        } else {
            requestURLString += "\(center.longitude),\(center.latitude),\(zoom)/"
        }
{'fraction_non_alphanumeric': 0.12188788758209868, 'fraction_numerical': 0.027188025049641056, 'mean_word_length': 1.9415992812219227, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 20, 'https://': 2, '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': '1631949', 'n_tokens_mistral': 2181, 'n_tokens_neox': 1987, 'n_words': 483}