Skip to content

Instantly share code, notes, and snippets.

@cherniag
cherniag / extend HystrixObservableCommand
Last active August 21, 2019 13:26
Hystrix reactive command
import com.netflix.hystrix.HystrixCommandGroupKey;
import com.netflix.hystrix.HystrixCommandKey;
import com.netflix.hystrix.HystrixObservableCommand;
import reactor.core.publisher.Mono;
import rx.Observable;
import rx.RxReactiveStreams;
class AsyncCommand extends HystrixObservableCommand<SourceAwareRestResponse> {
private final Mono<HttpResponse> adaptee;
private final Callable<T> fallbackProvider;
@cherniag
cherniag / How can I inspect html element that disappears from DOM on lost focus?
Created January 23, 2019 14:28
How can I inspect html element that disappears from DOM on lost focus?
type this in the Console:
setTimeout(() => { debugger; }, 5000)
Then you've got 5 seconds (or change the value to anything else) to make whatever you want to debug appear.
None of the other answers worked for me - the DOM tree kept getting modified (i.e. stuff I care about disappeared) right before the script paused.
@cherniag
cherniag / manual-uninstall-paragon-ntfs.sh
Created January 5, 2019 14:40 — forked from guycalledseven/manual-uninstall-paragon-ntfs.sh
Manually remove Paragon NTFS v15 leftovers MacOS
# after appcleaner does his magic, do this
sudo rm -rf "/Library/Application Support/Paragon Software/"
sudo rm /Library/LaunchDaemons/com.paragon-software.installer.plist
sudo rm /Library/LaunchDaemons/com.paragon-software.ntfs.loader.plist
sudo rm /Library/LaunchDaemons/com.paragon-software.ntfsd.plist
sudo rm /Library/LaunchAgents/com.paragon-software.ntfs.notification-agent.plist
sudo rm -rf /Library/Filesystems/ufsd_NTFS.fs/
sudo rm -rf /Library/PrivilegedHelperTools/com.paragon-software.installer
sudo rm -rf /Library/Extensions/ufsd_NTFS.kext/
Add hive2 to IDEA:
/Users/gennadiy.chernyaev/Downloads/curator-framework-2.6.0.jar
/Users/gennadiy.chernyaev/Downloads/hive-jdbc-2.0.0-standalone.jar
/Users/gennadiy.chernyaev/Downloads/curator-client-4.0.1.jar
/Users/gennadiy.chernyaev/Downloads/zookeeper-3.4.11.jar
/Users/gennadiy.chernyaev/Downloads/hive-common-2.0.0.jar
/Users/gennadiy.chernyaev/Downloads/hive-service-2.0.0.jar
/Users/gennadiy.chernyaev/Downloads/hadoop-common-3.1.0.jar
@cherniag
cherniag / Spring Data Hibernate native query with Pageable
Last active June 13, 2022 14:10
Spring Data Hibernate native query with Pageable
According to Example 50 at Using @Query from spring-data documentation this is possible specifying the query itself and a countQuery, like this:
public interface UserRepository extends JpaRepository<User, Long> {
@Query(value = "SELECT * FROM USERS WHERE LASTNAME = ?1",
countQuery = "SELECT count(*) FROM USERS WHERE LASTNAME = ?1",
nativeQuery = true)
Page<User> findByLastname(String lastname, Pageable pageable);
}
solution:
@cherniag
cherniag / Spark UDF filter
Created June 11, 2018 15:35
Spark UDF to filter map's key
// given - column with type Map<String, String>
import static org.apache.spark.sql.functions.callUDF;
import static org.apache.spark.sql.functions.lit;
import static org.apache.spark.sql.functions.col;
// define UDF
private UserDefinedFunction keyContains = functions.udf(
(scala.collection.Map<String, String> m, String key) -> m.contains(key),
@cherniag
cherniag / Spring application event
Last active June 11, 2018 12:36
Spring application event after transaction commit
need to perform some actions on entity after it had been commited using spring app events?
Use (instead of @EventListener):
@TransactionalEventListener(classes = MyEvent.class)
(note that inside new transaction is required to perform actions!)
https://spring.io/blog/2015/02/11/better-application-events-in-spring-framework-4-2
https://dzone.com/articles/transaction-synchronization-and-spring-application
@cherniag
cherniag / complicated jpa criteria api
Created April 17, 2018 12:56
complicated jpa criteria api
// Select Page with sorts and filters by children entities and distinct parent
// 1. Create DTO with sortable fields and id of parent, perform paging, sorting and filtering over this DTO
CriteriaQuery<ParentEntityDto> parentEntityQuery = cb.createQuery(ParentEntityDto.class);
Root<ParentEntity> parentEntityRoot = query.from(ParentEntity.class);
// filter here as usual, no special treatment
Predicate predicate = ...
parentEntityQuery.where(predicate);
parentEntityQuery.distinct(true);
// need to prevent duplication in select and order
@cherniag
cherniag / Hibernate predicate
Last active April 17, 2018 12:58
Hibernate criteria query predicate avg value of children one to many collection
@Override
public Predicate toPredicate(Root<ParentEntity> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
List<Predicate> predicates = new ArrayList<>();
if (filters.isEmpty()) {
return cb.conjunction();
}
Subquery<Long> countChildren = query.subquery(Long.class);
Root<ChildEntity> countChildrenRoot = countVotes.from(ChildEntity.class);