Skip to content

Instantly share code, notes, and snippets.

View cy6erGn0m's full-sized avatar
🦎

Sergey Mashkov cy6erGn0m

🦎
View GitHub Profile
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
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 =
@cy6erGn0m
cy6erGn0m / graham.hs
Last active December 22, 2015 21:38
Graham scan algorithm implementation in Haskell
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
@cy6erGn0m
cy6erGn0m / build.gradle
Last active December 23, 2015 10:23
Configuring testing library in kotlin
dependencies {
testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlinVersion"
}
@cy6erGn0m
cy6erGn0m / myFiles.erl
Created October 2, 2013 19:24
Yet another directory recursive delete function for Erlang
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);
@cy6erGn0m
cy6erGn0m / recursion1.kt
Created October 13, 2013 09:13
Kotlin tail recursive foldl demo
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
}
@cy6erGn0m
cy6erGn0m / recursion.kt
Created October 14, 2013 19:37
inner function annotation problem example
TailRecursive fun g2() {
TailRecursive fun g3(counter : Int, x : Any) : Unit {
if (counter > 0) { g3(counter - 1, "tail 97") }
}
g3(1000000, "test")
}
trait Test {
val test : String
}
class TestImpl (test : String) : Test {
override val test = test
}
@cy6erGn0m
cy6erGn0m / kotlin-ehcache.kt
Created February 5, 2016 15:59
Kotlin ehcache example
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))
@cy6erGn0m
cy6erGn0m / JettyClientTest.kt
Created July 28, 2016 15:10
Jetty HTTP client issue testcase
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.*