<commit_before>package com.gm.soundzones

import android.os.Environment
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentTransaction
import android.support.v7.app.AppCompatActivity
import android.text.TextUtils
import android.util.Log
import android.view.View
import android.widget.TextView
import java.io.File
import kotlinx.coroutines.experimental.CommonPool
import kotlinx.coroutines.experimental.channels.Channel
import kotlinx.coroutines.experimental.launch
import java.io.PrintWriter
import java.io.StringWriter
import java.text.SimpleDateFormat
import java.util.*
import kotlin.coroutines.experimental.Continuation
import kotlin.coroutines.experimental.suspendCoroutine

/**
 * Created by <NAME> on 25/09/2017.
 */
fun AppCompatActivity.loadFragment(addToBackStack: Boolean = false, load: FragmentTransaction.() -> Any) {
    val fragmentTransaction = supportFragmentManager
            .beginTransaction();

    val fragmentName = fragmentTransaction.load()
    if (addToBackStack) {
        fragmentTransaction.addToBackStack(fragmentName.javaClass.simpleName)
    }
    fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
    fragmentTransaction.commit()
}

private val LOG_DATE_FORMAT= SimpleDateFormat("dd-MM HH:mm:ss.SSS", Locale.getDefault())
private val logFile= File(Environment.getExternalStorageDirectory(),"soundzones.log")
private var startWriteLog:Continuation<Unit>?=null;
internal var hasWritePermission =false
    set(value) {
        field=value
        if(value) startWriteLog?.resume(Unit)
    }
private val logChannel:Channel<LogInfo> by lazy {
    launch(CommonPool){
        if(!hasWritePermission) suspendCoroutine<Unit> {
            startWriteLog=it
        }
        while (!logChannel.isClosedForReceive) {
            val (message, timestamp, exception) = logChannel.receive()
            logFile.appendText("<${LOG_DATE_FORMAT.format(Date(timestamp))}> $message\n${StringWriter().also {
                exception?.printStackTrace(PrintWriter(it))
            }}")
        }
    }
    Channel<LogInfo>(Channel.UNLIMITED)
}<commit_msg>frags<commit_after>package com.gm.soundzones

import android.os.Environment
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentTransaction
import android.support.v7.app.AppCompatActivity
import android.text.TextUtils
import android.util.Log
import android.view.View
import android.widget.TextView
import java.io.File
import kotlinx.coroutines.experimental.CommonPool
import kotlinx.coroutines.experimental.channels.Channel
import kotlinx.coroutines.experimental.launch
import java.io.PrintWriter
import java.io.StringWriter
import java.text.SimpleDateFormat
import java.util.*
import kotlin.coroutines.experimental.Continuation
import kotlin.coroutines.experimental.suspendCoroutine

/**
 * Created by <NAME> on 25/09/2017.
 */
fun AppCompatActivity.loadFragment(addToBackStack: Boolean = false, load: FragmentTransaction.() -> Any) {
    val fragmentTransaction = supportFragmentManager
            .beginTransaction();

    val fragmentName = fragmentTransaction.load()
    if (addToBackStack) {
        fragmentTransaction.addToBackStack(fragmentName.javaClass.simpleName)
    }
    fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
    fragmentTransaction.commit()
}

private val LOG_DATE_FORMAT= SimpleDateFormat("dd-MM HH:mm:ss.SSS", Locale.US)
private val logFile= File(Environment.getExternalStorageDirectory(),"soundzones.log")
private var startWriteLog:Continuation<Unit>?=null;
internal var hasWritePermission =false
    set(value) {
        field=value
        if(value) startWriteLog?.resume(Unit)
    }
private val logChannel:Channel<LogInfo> by lazy {
    launch(CommonPool){
        if(!hasWritePermission) suspendCoroutine<Unit> {
            startWriteLog=it
        }
        while (!logChannel.isClosedForReceive) {
            val (message, timestamp, exception) = logChannel.receive()
            logFile.appendText("<${LOG_DATE_FORMAT.format(Date(timestamp))}> $message\n${StringWriter().also {
                exception?.printStackTrace(PrintWriter(it))
            }}")
        }
    }
    Channel<LogInfo>(Channel.UNLIMITED)
}
{'fraction_non_alphanumeric': 0.09981078524124881, 'fraction_numerical': 0.005203405865657522, 'mean_word_length': 4.456774193548387, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, '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': '4142752', 'n_tokens_mistral': 1214, 'n_tokens_neox': 1187, 'n_words': 206}