Skip to content

Instantly share code, notes, and snippets.

View antonlogvinenko's full-sized avatar
☠️
kept you waiting huh

antonlogvinenko

☠️
kept you waiting huh
View GitHub Profile
@antonlogvinenko
antonlogvinenko / recursive-dir-list.hs
Created December 4, 2016 20:18
Recursive directory listing
import Control.Monad.Trans.List (ListT(..))
import Control.Monad.Trans (lift)
import System.Directory (getDirectoryContents, doesDirectoryExist)
listDir :: FilePath -> ListT IO FilePath
listDir path = do
isDirectory <- lift $ doesDirectoryExist path
if not isDirectory
then ListT $ return [path]
else do
@antonlogvinenko
antonlogvinenko / java8_rt_bytecode_frequency.textile
Created December 4, 2016 18:57
Java 8 standard library bytecode frequency
OpCpde Frequency
aload_0 10.7155%
invokevirtual 6.5737%
getfield 5.4156%
aload_1 4.0842%
dup 3.7698%
invokespecial 3.5982%
iload 3.2671%
aload 3.1602%
goto 2.3347%
@antonlogvinenko
antonlogvinenko / guava-opcodes.textile
Created December 4, 2016 12:47
Guava class files: opcodes frequency
OpCpde Frequency
aload_0 8.9024%
invokestatic 7.9831%
invokevirtual 5.9661%
dup 5.6271%
aload_1 5.0123%
invokeinterface 4.1291%
nop 4.1291%
getfield 3.6463%
aastore 3.6388%
@antonlogvinenko
antonlogvinenko / gist:3b17622e39a4be811bb1
Created March 22, 2015 12:36
Almost Java Reader Monad
package anton.logvinenko;
import javafx.util.Pair;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;
public class Parser<S> {
@antonlogvinenko
antonlogvinenko / bdb2mongo.java
Created July 28, 2014 12:23
BerkeleyDB 2 MongoDB migration
package com.farpost.imagestorage;
import com.farpost.imagestorage.duplicate.index.mongo.MongoDbIndex;
import com.mongodb.MongoClient;
import org.bson.types.Binary;
import java.io.*;
import java.math.BigInteger;
import java.net.UnknownHostException;
import java.util.List;
@antonlogvinenko
antonlogvinenko / clojurethreading
Last active May 27, 2017 03:16
clojure threading in haskell
-- The idea is to have Clojure threading macro '->>' in Haskell:
-- (->> 1 repeat (map (* 2)) (take 10) (map (* 2)) (map (+ 40)) (foldl + 0))
-- where (->> x f1 f2 f3 f4) means literally this: "f4 (f3 (f2 (f1 x)))"
-- Same in Haskell: "f4 . f3 . f2 . f1 $ x"
-- Let's try to implement it
data Apply a b = Apply { x :: a, f :: a -> b }
(->>) :: a -> (a -> b) -> Apply a b
(->>) x f = Apply x f
@antonlogvinenko
antonlogvinenko / gist:33f567656ff18abf4b49
Last active August 29, 2015 14:02
image resize problem
@Test
public void test() throws IOException {
//BufferedImage bi = bytesToBufferedImage(readBytesFromFile(this, "1401403088318_default.png"));
//pls change readBytesFromFile if not storing file in /resources
BufferedImage bi = ImageIO.read(new ByteArrayInputStream(readBytesFromFile(this, "1401403088318_default.png")));
System.out.println(bi.getColorModel().getColorSpace().getType());
if (bi.getType() == BufferedImage.TYPE_USHORT_GRAY) {
package com.farpost.search.statbuilder.termset;
import com.farpost.search.statbuilder.util.OrderedSource;
import com.farpost.search.statbuilder.util.Source;
import com.sun.istack.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.List;
package com.farpost.search.statbuilder.termset;
import com.farpost.search.statbuilder.util.OrderedSource;
import com.farpost.search.statbuilder.util.Source;
import com.sun.istack.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.List;
@antonlogvinenko
antonlogvinenko / gist:6558266
Created September 14, 2013 02:11
reflection-interop
package com.farpost;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.*;
final public class Bla {
private Bla() {
}