This file contains 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 cg; | |
import java.util.List; | |
import java.util.ArrayList; | |
import java.util.regex.Pattern; | |
import java.util.regex.Matcher; | |
/** | |
* @author Sergey Mashkov (cy6erGn0m) | |
* @since 04.03.13 |
This file contains 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
data Node a = Node a (Node a) (Node a) | Empty | |
treeHeight :: Node a -> Int | |
treeHeight Empty = 0 | |
treeHeight tree = treeHeightImpl [(1, tree)] 1 | |
where | |
treeHeightImpl :: [ (Int, (Node a)) ] -> Int -> Int | |
treeHeightImpl ((currentDepth, (Empty)) : xs) maxDepth = treeHeightImpl xs maxDepth | |
treeHeightImpl [] maxDepth = maxDepth | |
treeHeightImpl ((currentDepth, (Node _ left right)) : xs) maxDepth = |
This file contains 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 Data.List (sortBy, minimumBy, delete) | |
data Point = Point {x :: Double, y :: Double } deriving (Show, Eq) | |
add (Point ax ay) (Point bx by) = Point (ax + bx) (ay + by) | |
sub :: Point -> Point -> Point | |
sub (Point ax ay) (Point bx by) = Point (ax - bx) (ay - by) | |
mult :: Point -> Point -> Double |
This file contains 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" | |
} |
This file contains 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
ensureDirSlash(Dir, Child) -> | |
case lists:suffix("/", Dir) of | |
true -> Dir ++ Child; | |
false -> Dir ++ "/" ++ Child | |
end. | |
-spec deleteDir(Dir :: nonempty_string()) -> none(). | |
deleteDir(Dir) -> | |
case {filelib:is_dir(Dir), isFileOrLink(Dir)} of | |
{_, true} -> throw("The specified path is not a directory: " ++ Dir); |
This file contains 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, A> Iterator<T>.foldl(acc : A, foldFunction : (e : T, acc : A) -> A) : A = | |
if (!hasNext()) acc | |
else foldl(foldFunction(next(), acc), foldFunction) | |
val sum = (1..1000000).iterator().foldl(0) { (e : Int, acc : Long) -> | |
acc + e | |
} |
This file contains 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
TailRecursive fun g2() { | |
TailRecursive fun g3(counter : Int, x : Any) : Unit { | |
if (counter > 0) { g3(counter - 1, "tail 97") } | |
} | |
g3(1000000, "test") | |
} |
This file contains 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
trait Test { | |
val test : String | |
} | |
class TestImpl (test : String) : Test { | |
override val test = test | |
} |
This file contains 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 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.* |