This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun <T : Comparable<T>> mergeSort(input: Array<T>) { | |
mergeSort(input, naturalOrder()) | |
} | |
fun <T> mergeSort(input: Array<T>, comparator: Comparator<T>) { | |
if (input.size < 2) return | |
val tempSpace = input.copyOf() | |
for (windowSize in generateSequence(1) { it * 2 }.takeWhile { it < input.size }) { | |
for (segment in 0 until input.size / windowSize step 2) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlinx.cinterop.* | |
import org.ssh.* | |
fun main(): Unit = memScoped { | |
val session = ssh_new() ?: return | |
val port = alloc<IntVar>() | |
port.value = 22 | |
val verbosity = alloc<UIntVar>() | |
verbosity.value = SSH_LOG_PROTOCOL |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Please note that you don't even need kotlin-reflect.jar | |
class C { | |
val f: String | |
get() = "ok" | |
} | |
fun usage() { | |
val fn = makeFunction(C::f) | |
println(fn(C())) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlinx.coroutines.* | |
import kotlinx.coroutines.channels.* | |
import java.util.concurrent.locks.* | |
import kotlin.coroutines.* | |
private val MyEventLoop: CoroutineDispatcher = TODO() | |
/** | |
* This is simplified blocking adapter example. | |
* NEVER use in production as it is just clarification, not actual implementation |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private val XFrameOptionsAttribute = AttributeKey<XFrameOptions>("X-Frame-Options") | |
sealed class XFrameOptions { | |
object Deny : XFrameOptions() { | |
override fun toString() = "deny" | |
} | |
object SameOrigin : XFrameOptions() { | |
override fun toString() = "sameorigin" | |
} | |
class AllowFrom(val url: String) : XFrameOptions() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sealed class XFrameOptions { | |
object Deny : XFrameOptions() { | |
override fun toString() = "deny" | |
} | |
object SameOrigin : XFrameOptions() { | |
override fun toString() = "sameorigin" | |
} | |
class AllowFrom(val url: String) : XFrameOptions() { | |
override fun toString(): String = "allow-from $url" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.jetbrains.ktor.client | |
import org.eclipse.jetty.http2.client.* | |
import org.eclipse.jetty.http2.client.http.* | |
import org.eclipse.jetty.http2.server.* | |
import org.eclipse.jetty.server.* | |
import org.eclipse.jetty.servlet.* | |
import org.eclipse.jetty.util.thread.* | |
import org.junit.* | |
import java.util.concurrent.* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val cacheManager = CacheManagerBuilder.newCacheManagerBuilder() | |
.with(CacheManagerPersistenceConfiguration(storagePath)) | |
.withCache("kweetsCache", | |
CacheConfigurationBuilder.newCacheConfigurationBuilder<Int, Kweet>() | |
.withResourcePools(ResourcePoolsBuilder.newResourcePoolsBuilder() | |
.heap(1000, EntryUnit.ENTRIES) | |
.offheap(10, MemoryUnit.MB) | |
.disk(100, MemoryUnit.MB, true) | |
) | |
.buildConfig(Int::class.javaObjectType, Kweet::class.java)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun findFreePort() = ServerSocket(0).use { it.localPort } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dependencies { | |
testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlinVersion" | |
} |
NewerOlder