<commit_before>import UIKit
import AVFoundation

final class ScanningAccountCreationViewController: UIViewController,
AVCaptureMetadataOutputObjectsDelegate {
  @IBOutlet weak var allowCameraAccessLabel: UILabel!
  var delegate: AccountCreationDelegate?
  private var session = AVCaptureSession()
  private let output = AVCaptureMetadataOutput()
  private var layer: AVCaptureVideoPreviewLayer?

  @IBAction func didPressCancel(sender: UIBarButtonItem) {
    output.setMetadataObjectsDelegate(nil, queue: nil)
    presentingViewController?.dismissViewControllerAnimated(true, completion: nil)
  }

  override func viewDidLoad() {
    super.viewDidLoad()
    let device = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo)
    if let input = try? AVCaptureDeviceInput(device: device) {
      session.addInput(input)
      session.addOutput(output)
      output.setMetadataObjectsDelegate(self, queue: dispatch_get_main_queue())
      output.metadataObjectTypes = [AVMetadataObjectTypeQRCode]
      layer = AVCaptureVideoPreviewLayer(session: session)
      layer!.videoGravity = AVLayerVideoGravityResizeAspectFill
      view.layer.addSublayer(layer!)
      session.startRunning()
    } else {
      allowCameraAccessLabel.hidden = false
    }
  }

  override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()
    layer?.frame = view.layer.bounds
    switch UIDevice.currentDevice().orientation {
    case .LandscapeLeft:
      layer?.connection.videoOrientation = .LandscapeRight
    case .LandscapeRight:
      layer?.connection.videoOrientation = .LandscapeLeft
    default:
      layer?.connection.videoOrientation = .Portrait
    }
  }

  // MARK: AVCaptureMetadataOutputObjectsDelegate

  func captureOutput(
    captureOutput: AVCaptureOutput!,
    didOutputMetadataObjects metadataObjects: [AnyObject]!,
    fromConnection connection: AVCaptureConnection!) {
      guard metadataObjects.count > 0,
        let metadataObject = metadataObjects.first as? AVMetadataMachineReadableCodeObject
        where metadataObject.type == AVMetadataObjectTypeQRCode,
        let url = NSURL(string: metadataObject.stringValue),
        let account = Account(url: url) else { return }
      output.setMetadataObjectsDelegate(nil, queue: nil)
      presentingViewController?.dismissViewControllerAnimated(true) {
        self.delegate?.createAccount(account)
      }
  }
}<commit_msg>Save account before dismissing scanning controller<commit_after>import UIKit
import AVFoundation

final class ScanningAccountCreationViewController: UIViewController,
AVCaptureMetadataOutputObjectsDelegate {
  @IBOutlet weak var allowCameraAccessLabel: UILabel!
  var delegate: AccountCreationDelegate?
  private var session = AVCaptureSession()
  private let output = AVCaptureMetadataOutput()
  private var layer: AVCaptureVideoPreviewLayer?

  @IBAction func didPressCancel(sender: UIBarButtonItem) {
    output.setMetadataObjectsDelegate(nil, queue: nil)
    presentingViewController?.dismissViewControllerAnimated(true, completion: nil)
  }

  override func viewDidLoad() {
    super.viewDidLoad()
    let device = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo)
    if let input = try? AVCaptureDeviceInput(device: device) {
      session.addInput(input)
      session.addOutput(output)
      output.setMetadataObjectsDelegate(self, queue: dispatch_get_main_queue())
      output.metadataObjectTypes = [AVMetadataObjectTypeQRCode]
      layer = AVCaptureVideoPreviewLayer(session: session)
      layer!.videoGravity = AVLayerVideoGravityResizeAspectFill
      view.layer.addSublayer(layer!)
      session.startRunning()
    } else {
      allowCameraAccessLabel.hidden = false
    }
  }

  override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()
    layer?.frame = view.layer.bounds
    switch UIDevice.currentDevice().orientation {
    case .LandscapeLeft:
      layer?.connection.videoOrientation = .LandscapeRight
    case .LandscapeRight:
      layer?.connection.videoOrientation = .LandscapeLeft
    default:
      layer?.connection.videoOrientation = .Portrait
    }
  }

  // MARK: AVCaptureMetadataOutputObjectsDelegate

  func captureOutput(
    captureOutput: AVCaptureOutput!,
    didOutputMetadataObjects metadataObjects: [AnyObject]!,
    fromConnection connection: AVCaptureConnection!) {
      guard metadataObjects.count > 0,
        let metadataObject = metadataObjects.first as? AVMetadataMachineReadableCodeObject
        where metadataObject.type == AVMetadataObjectTypeQRCode,
        let url = NSURL(string: metadataObject.stringValue),
        let account = Account(url: url) else { return }
      output.setMetadataObjectsDelegate(nil, queue: nil)
      delegate?.createAccount(account)
      presentingViewController?.dismissViewControllerAnimated(true, completion: nil)
  }
}
{'fraction_non_alphanumeric': 0.07584211613969828, 'fraction_numerical': 0.0004133085348212441, 'mean_word_length': 4.506257110352673, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '5655642', 'n_tokens_mistral': 1276, 'n_tokens_neox': 1276, 'n_words': 259}