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.io.InputStream; | |
import java.io.OutputStreamWriter; | |
import java.net.InetAddress; | |
import java.net.Socket; | |
/** | |
* @author Sergey Mashkov aka cy6erGn0m | |
* @since 08.06.12 |
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 org.fusesource.jansi.Ansi; | |
import org.fusesource.jansi.AnsiConsole; | |
/** | |
* User: Sergey Mashkov | |
* Date: 6/21/12 | |
*/ | |
public class Main { |
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
def map = [:] | |
map.test = 1 | |
println map.test | |
map.xxx = [ aa : 'aa'] | |
println map.xxx.aa |
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.io.*; | |
import java.nio.file.Files; | |
import java.nio.file.Path; | |
import java.nio.file.Paths; | |
import java.util.regex.Matcher; | |
import java.util.regex.Pattern; | |
/** |
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
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") | |
} |
OlderNewer