Skip to content

Instantly share code, notes, and snippets.

@pianovwork
pianovwork / App
Created November 20, 2018 18:25
Cache based on session
@SpringBootApplication
@EnableCaching
@Import({
CacheCleanupOnSessionDestroyingListener.class
})
public class TestApp {
public static void main(String[] args) {
SpringApplication.run(TestApp.class, args);
}
@pianovwork
pianovwork / OneOf.java
Last active April 23, 2019 02:45
JSR-303 OneOf
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import javax.validation.Constraint;
import javax.validation.Payload;
import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
import static java.lang.annotation.ElementType.CONSTRUCTOR;
import static java.lang.annotation.ElementType.FIELD;
@pianovwork
pianovwork / README.MD
Last active April 23, 2019 02:50
Open Shift helpers

Openshift helpers:

oc-pod-name app_name [namespace]

oc-logs app_name [namespace]

oc-tunnel namespace app_name port

oc-tunnel namespace app_name s_port:d_port

@pianovwork
pianovwork / find_total_posible_questions_for_quiz.sql
Last active April 23, 2019 02:46
Find Total Possible Questions for Practice Test Quiz
-- vtw_id data
-- exam_1 {items: [q1,q2,q3]}
-- exam_2 {items: [q3,q4]}
-- quiz_3 {examVtwId: ['exam_1', 'exam_2']}
-- quiz_4 {examVtwId: ['exam_2'] }
-- Result:
-- quiz_vtw total_question count(exam)
-- quiz_4 2 1
-- quiz_3 5 2
public class JsonNodeHelper {
/**
* remove recursively all blank nodes (null, missed, array/object with size 0 and blank text)
*
* @param node target node where need to remove blank nodes
*/
public static void removeBlankNodes(JsonNode node) {
if (node == null) {
return;
}
@pianovwork
pianovwork / .gitconfig
Last active October 26, 2021 00:11
git config
[core]
excludesfile = ~/.gitignore
autocrlf = input
editor = vim
[user]
name = Ievgen.Pianov
email = pyanov.eugen@gmail.com
[alias]
sync = pull --rebase origin develop
unstash = stash apply
@pianovwork
pianovwork / SmartLoggerFactory.java
Created March 30, 2016 23:05
Smart Logger Factory
public final class SmartLoggerFactory {
public static org.slf4j.Logger getLogger() {
final Throwable ex = new Throwable();
ex.fillInStackTrace();
String clazz = ex.getStackTrace()[1].getClassName();
return org.slf4j.LoggerFactory.getLogger(clazz);
}
private SmartLoggerFactory() {
@pianovwork
pianovwork / CompositeValidator.java
Last active April 20, 2019 08:38
Spring Validation Setup ~ CompositeValidator
@Component
public class CompositeValidator implements SmartValidator {
@Autowired
private List<Validator> validators = Collections.emptyList();
@PostConstruct
public void init() {
Collections.sort(validators, AnnotationAwareOrderComparator.INSTANCE);
}
@pianovwork
pianovwork / MinAgeValidationExample.java
Created March 10, 2016 23:13
json-schema fge/json-schema-validator: minAge
import java.io.IOException;
import org.joda.time.DateTimeZone;
import org.joda.time.LocalDate;
import org.joda.time.Period;
import com.fasterxml.jackson.databind.JsonNode;
import com.github.fge.jackson.JsonLoader;
import com.github.fge.jackson.NodeType;
import com.github.fge.jsonschema.cfg.ValidationConfiguration;
import com.github.fge.jsonschema.core.exceptions.ProcessingException;
import com.github.fge.jsonschema.core.keyword.syntax.checkers.helpers.TypeOnlySyntaxChecker;