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
(write-with [this type user-space-id history]
(sql/with-connection {:datasource this}
(let [table :history2
where-params ["type = ? and user_space_id = ?" type user-space-id]
record {:user_space_id user-space-id, :type type, :history history}]
(sql/transaction
(let [result (sql/update-values table where-params record)]
(if (zero? (first result))
(locking this
(sql/insert-values table (keys record) (vals record))
(write-with [this type user-space-id history]
(sql/with-connection {:datasource this}
(let [table :history2
where-params ["type = ? and user_space_id = ?" type user-space-id]
record {:user_space_id user-space-id, :type type, :history history}]
(sql/transaction
(let [result (sql/update-values table where-params record)]
(if (zero? (first result))
(locking this
(sql/insert-values table (keys record) (vals record))
package com.farpost;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import static java.lang.System.nanoTime;
public class Main {
@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() {
}
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: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) {
@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 / 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 / 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> {