Skip to content

Instantly share code, notes, and snippets.

Avatar
🦎

Sergey Mashkov cy6erGn0m

🦎
View GitHub Profile
@cy6erGn0m
cy6erGn0m / Main.java
Created Jun 8, 2012
Simplest HTTP request example
View Main.java
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
@cy6erGn0m
cy6erGn0m / Main.java
Created Jun 21, 2012
Simple example jansi library
View Main.java
package cg;
import org.fusesource.jansi.Ansi;
import org.fusesource.jansi.AnsiConsole;
/**
* User: Sergey Mashkov
* Date: 6/21/12
*/
public class Main {
@cy6erGn0m
cy6erGn0m / test.groovy
Created Aug 17, 2012
Groovy dot "override"
View test.groovy
def map = [:]
map.test = 1
println map.test
map.xxx = [ aa : 'aa']
println map.xxx.aa
@cy6erGn0m
cy6erGn0m / JavaRegexpTest.java
Created Mar 3, 2013
Regexp performance difference example
View JavaRegexpTest.java
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;
/**
View JavaRegexpTest2.java
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
View rwh_ch03_08.hs
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 Dec 22, 2015
Graham scan algorithm implementation in Haskell
View graham.hs
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 / myFiles.erl
Created Oct 2, 2013
Yet another directory recursive delete function for Erlang
View myFiles.erl
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 Oct 13, 2013
Kotlin tail recursive foldl demo
View recursion1.kt
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 Oct 14, 2013
inner function annotation problem example
View recursion.kt
TailRecursive fun g2() {
TailRecursive fun g3(counter : Int, x : Any) : Unit {
if (counter > 0) { g3(counter - 1, "tail 97") }
}
g3(1000000, "test")
}