Skip to content

Instantly share code, notes, and snippets.

View ufuk's full-sized avatar
🤔

Ufuk Uzun ufuk

🤔
View GitHub Profile
@okanmenevseoglu
okanmenevseoglu / user-management.sql
Created February 23, 2018 06:45
Creating User and Giving Granular Access to the User on PostgreSQL
-- Create new user to the DB
CREATE USER {{username}} WITH ENCRYPTED PASSWORD {{password}};
-- Give access connection to the wanted DB
GRANT CONNECT ON DATABASE {{dbname}} TO {{username}};
-- Give access to the wanted schema
GRANT USAGE ON SCHEMA {{schemaname}} TO {{userName}};
-- Give select access to the sequences for the wanted schema
@baybatu
baybatu / mockito-deep-stubs.md
Last active September 21, 2020 07:48
Mockito deep stubs for nested objects
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
private NestedObject nestedObject;

example usage in a test method:

when(nestedObject.getStatusInfo().getValue().getStatus()).thenReturn(1);
@baybatu
baybatu / ThreadPoolTaskExecutorWithMdcPropagation.java
Last active December 20, 2018 11:00
Propogate MDC context into newly created thread pool
public class ThreadPoolTaskExecutorWithMdcPropagation extends ThreadPoolExecutor {
private static final Logger LOGGER = LoggerFactory.getLogger(ThreadPoolTaskExecutorWithMdcPropagation.class);
private final Map<String, String> parentMdcContextMap;
public ThreadPoolTaskExecutorWithMdcPropagation(int corePoolSize, int maxPoolSize, long keepAliveTime, TimeUnit keepAliveTimeUnit) {
super(corePoolSize, maxPoolSize, keepAliveTime, keepAliveTimeUnit, new LinkedBlockingQueue<>());
parentMdcContextMap = MDC.getCopyOfContextMap();
}
@baybatu
baybatu / rabbitmq-delay-message-consume.md
Last active October 13, 2022 10:14
RabbitMQ: mesajı geciktirerek tüketmek

RabbitMQ: Mesajı Geciktirerek Tüketmek

  • delay-exchange: Geciktirilecek mesajın bırakıldığı exchange.
  • delay-queue: delay-exchange'e bağlı. Herhangi bir tüketicisi olmamalı.
  • ana-exchange: Geciktirilmeden tüketilmek istenen mesajların bırakılabileceği exchange.
  • ana-queue: ana-exchange'e bağlı kuyruk. Tüketicisi var.

delay-queue şu parametrelerle oluşturulur:

  • x-dead-letter-exchange: -- boş
  • x-message-ttl: 3000 -- mesajın bekletileceği milisaniye
@baybatu
baybatu / PaginationThroughHttpHeadersResponseAdvice.java
Last active August 5, 2021 06:59
Managing pagination through HTTP headers on Spring Boot. `PageResponseAdvice` intercepts responses in `PageResponse` type and puts pagination related fields into HTTP response headers.
@ControllerAdvice
public class PageResponseAdvice implements ResponseBodyAdvice<Object> {
@Override
public boolean supports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType) {
return PageResponse.class.isAssignableFrom(returnType.getParameterType());
}
@Override
public Object beforeBodyWrite(Object body,
@muratcanbur
muratcanbur / BaseMockitoTest.kt
Last active April 15, 2019 10:50 — forked from ufuk/BaseMockito2JUnit4Test.java
Performs "verify no more interactions" check automatically for all mock objects (works with Mockito version 2). For detailed description: https://ufukuzun.wordpress.com/2019/04/09/ne-olup-bittiginden-habersiz-testlere-derman-mockscollector/ (Turkish)
@RunWith(AndroidJUnit4::class)
abstract class BaseMockitoTest {
private val mockitoMocksCollector = MockitoMocksCollector()
@After
fun after() {
val allMocks = mockitoMocksCollector.getAllMocks()
allMocks.forEach { mock ->
verifyNoMoreInteractions(mock)
@yusufcakal
yusufcakal / gist:73bba046739551dfe31dd5134b9e375c
Created June 11, 2019 16:39
SpringOne19' Istanbul Useful Links
https://www.callicoder.com/hibernate-spring-boot-jpa-embeddable-demo/
https://www.baeldung.com/java-optional-or-else-vs-or-else-get
https://refactoring.guru/smells/feature-envy
https://www.mkyong.com/unittest/junit-4-tutorial-2-expected-exception-test/
https://www.javacodegeeks.com/2013/02/testing-expected-exceptions-with-junit-rules.html
https://www.geeksforgeeks.org/luhn-algorithm/
http://baddotrobot.com/blog/2012/03/27/expecting-exception-with-junit-rule/
https://github.com/r2dbc
https://docs.spring.io/spring/docs/current/spring-framework-reference/web-reactive.html
https://github.com/snicoll-demos/spring-boot-migration/tree/master/src/main/java/com/example/speakerservice
@yusufcakal
yusufcakal / TextMasker.java
Created January 22, 2020 11:31
It can use text mask to bounds of text certain begin and end indices. Enjoy your data driven test via spock framework :)
public class TextMasker {
public static String mask(String text, int begin, int end) {
if (Objects.isNull(text)) {
return null;
}
if (areIndexesInBoundOfText(text, begin, end)) {
String firstDisplayablePart = text.substring(0, begin);
String secondDisplayablePart = text.substring(end);
@baybatu
baybatu / active-forks.md
Created October 28, 2020 13:22
Find most active github forks easily
@baybatu
baybatu / finagle-http2-frame-logger.md
Last active December 24, 2020 10:30
Log http2 frames on a finagle service
import com.twitter.finagle.http2.param.FrameLoggerNamePrefix
val service =
        Http
          .client
          .withLabel("service-label")
          .configured(FrameLoggerNamePrefix(this.getClass.getName))
          .withHttp2
          .newService("localhost:8080")