Skip to content

Instantly share code, notes, and snippets.

View vy's full-sized avatar

Volkan Yazıcı vy

View GitHub Profile
@vy
vy / Throwables.java
Last active September 16, 2021 11:16
Utility method to stream exception causal chains in Java.
/*
* Copyright © 2021 Volkan Yazıcı ([email protected])
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@vy
vy / JsonReader.java
Created March 6, 2020 09:45
Single-file simple JSON parser for Java 8
/*
* Copyright 2020 Volkan Yazıcı
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@vy
vy / HikaricpMicrometerBug.java
Created June 13, 2019 19:49
/brettwooldridge/HikariCP/issues/1374
package com.vlkan;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import com.zaxxer.hikari.metrics.prometheus.PrometheusMetricsTrackerFactory;
import io.micrometer.core.instrument.Clock;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.prometheus.PrometheusConfig;
import io.micrometer.prometheus.PrometheusMeterRegistry;
import io.prometheus.client.CollectorRegistry;
@vy
vy / ReactorWorkbench.java
Last active April 16, 2019 14:34
Reactor backpressure-aware pull-push streaming example
package com.experiment.pubsub.pubsubdriver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Scheduler;
import reactor.core.scheduler.Schedulers;
import java.time.Duration;
@vy
vy / DemoSpringAppApplication.java
Created March 26, 2019 08:28
How to pass a Spring property to Log4j in a Spring Boot application
package com.vlkan.demo.spring;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import javax.annotation.PostConstruct;
@vy
vy / keybase.md
Created May 25, 2017 13:52
Keybase

Keybase proof

I hereby claim:

  • I am vy on github.
  • I am vy (https://keybase.io/vy) on keybase.
  • I have a public key whose fingerprint is F1A5 FC81 7614 255A 8E44 1A9A D37D 4387 C9BD 368E

To claim this, I am signing this object:

@vy
vy / tc-port-delay.sh
Last active May 18, 2021 21:36
Add 5s delay to outgoing traffic from port 34001
tc qdisc add dev eth0 root handle 1: prio
tc qdisc add dev eth0 parent 1:3 handle 30: netem delay 5s
tc filter add dev eth0 protocol ip parent 1:0 u32 match ip sport 34001 0xffff flowid 1:3
@vy
vy / Minimax.java
Last active December 23, 2015 04:29
Shortest minimax path algorithms.
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import java.util.*;
/**
* Implements methods to compute the shortest minimax paths in a graph.
*
* A minimax path is the shortest length path such that the
* maximum edge weight along a path is minimum. (See the Wikipedia <a
@vy
vy / AllPairsShortestPath.scala
Created February 28, 2013 12:57
Floyd-Warshall all-pairs-shortest-path algorithm in Scala.
/**
* Returns shortest paths between all pairs using Floyd-Warshall algorithm.
* Nodes are assumed to be enumerated without any holes and enumeration
* starts from 0.
*
* @param nodes the set of vertices
* @param links the map of edges with costs
* @return shortest paths between all pairs, including the source and destination
*/
def allPairsShortestPath(nodes: Set[Int], links: Map[Int, Set[Int]]): Map[Int, Map[Int, Seq[Int]]] = {
@vy
vy / MergeNodeAlgorithm.hpp
Created November 29, 2012 21:17
Merging Two Binary Search Trees in O(logn) Space
#ifndef MERGE_NODE_ALGORITHM_HPP
#define MERGE_NODE_ALGORITHM_HPP
template <class T>
class MergeNodeAlgorithm {
public:
virtual bool empty() const = 0;
virtual void pop() = 0;
virtual T get() const = 0;