Skip to content

Instantly share code, notes, and snippets.

View CDRussell's full-sized avatar

Craig Russell CDRussell

View GitHub Profile
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<author>{{.Site.Author.name}}</author>
<title>{{ if eq .Title .Site.Title }}{{ .Site.Title }}{{ else }}{{ with .Title }}{{.}} on {{ end }}{{ .Site.Title }}{{ end }}</title>
<link>{{ .Permalink }}</link>
<description>Recent content {{ if ne .Title .Site.Title }}{{ with .Title }}in {{.}} {{ end }}{{ end }}on {{ .Site.Title }}</description>
<generator>Hugo -- gohugo.io</generator>{{ with .Site.LanguageCode }}
<language>{{.}}</language>{{end}}{{ with .Site.Author.email }}
<managingEditor>{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}</managingEditor>{{end}}{{ with .Site.Author.email }}
<webMaster>{{.}}{{ with $.Site.Author.name }} ({{.}}){{end}}</webMaster>{{end}}{{ with .Site.Copyright }}
val itemsToAdd = 500_000
// val list = mutableListOf<Int>()
val tMutableList = measureNanoTime {
val list = mutableListOf<Int>()
for (i in 1..itemsToAdd) {
list += i
}
}
Timber.i("Using += on `MutableList<Int>` took ${TimeUnit.NANOSECONDS.toMillis(tMutableList)}ms")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
launch(Dispatchers.Main.immediate) {
log("A")
}
log("B")
}
override val coroutineContext: CoroutineContext
get() = Dispatchers.Main
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
launch(Dispatchers.Main) {
log("A")
}
log("B")
}
val result = measureExecution("Finished doing work", Log.INFO) {
foo.doSomeWork()
return foo.getResult()
}
measureExecution("Finished doing work") {
foo.doSomeWork()
}
inline fun <T> measureExecution(logMessage: String, logLevel: Int = Log.DEBUG, function: () -> T): T {
val startTime = System.nanoTime()
return function.invoke().also {
val difference = System.nanoTime() - startTime
Timber.log(logLevel, "$logMessage; took ${TimeUnit.NANOSECONDS.toMillis(difference)}ms")
}
}
@CDRussell
CDRussell / DisableWebSql.kt
Created December 18, 2018 14:37
Disabling WebSQL
val webView: WebView = findViewById(R.id.webView)
// disable Web SQL
webView.settings.databaseEnabled = false
val result = parse(url)
when (result) {
is ParseResult.ParsedData -> analyzeMimeType(result.mimeType)
is ParseResult.Error -> log(result.errorMessage)
}