<commit_before>//
//  HomeViewController.swift
//  Gradientor
//
//  Created by <NAME> on 2017/04/17.
//  Copyright © 2017 tnantoka. All rights reserved.
//

import UIKit

class HomeViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}<commit_msg>Generate gradient with random colors<commit_after>//
//  HomeViewController.swift
//  Gradientor
//
//  Created by <NAME> on 2017/04/17.
//  Copyright © 2017 tnantoka. All rights reserved.
//

import UIKit
import GameplayKit

import RxSwift

class HomeViewController: UIViewController {

    private let bag = DisposeBag()
    private let colors = Variable<[UIColor]>([])
    private let gradientLayer = CAGradientLayer()

    private var addItem: UIBarButtonItem!
    private var clearItem: UIBarButtonItem!

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        title = NSLocalizedString("Gradientor", comment: "")
        view.backgroundColor = .white
        navigationController?.isToolbarHidden = false

        view.layer.addSublayer(gradientLayer)

        addItem = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(addDidTap))
        clearItem = UIBarButtonItem(title: NSLocalizedString("Clear", comment: ""), style: .plain, target: self, action: #selector(clearDidTap))

        navigationItem.rightBarButtonItem = addItem
        toolbarItems = [clearItem]

        colors.asObservable()
            .subscribe(onNext: { [weak self] colors in
                guard let view = self?.view else { fatalError() }
                self?.gradientLayer.colors = colors.map { $0.cgColor }
                self?.gradientLayer.frame = view.bounds
            }).addDisposableTo(bag)
        colors.asObservable()
            .subscribe(onNext: { [weak self] colors in
                self?.updateUI(colors: colors)
            }).addDisposableTo(bag)

        clear()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

    // MARK - Utilities

    private func updateUI(colors: [UIColor]) {
        clearItem.isEnabled = colors.count > 0
    }

    private func randomColor() -> UIColor {
        let random = GKRandomSource()
        let color = UIColor(
            red: CGFloat(random.nextUniform()),
            green: CGFloat(random.nextUniform()),
            blue: CGFloat(random.nextUniform()),
            alpha: 1.0
        )
        return color
    }

    private func clear() {
        colors.value = [
            randomColor(),
            randomColor(),
        ]
    }

    // MARK - Actions

    @objc private func addDidTap(sender: Any) {
        colors.value.append(randomColor())
    }

    @objc private func clearDidTap(sender: Any) {
        clear()
    }
}
{'fraction_non_alphanumeric': 0.09641372141372141, 'fraction_numerical': 0.007276507276507277, 'mean_word_length': 2.352787456445993, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 8, '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': '5443005', 'n_tokens_mistral': 1097, 'n_tokens_neox': 1016, 'n_words': 302}