Skip to content

Instantly share code, notes, and snippets.

View cenkc's full-sized avatar
🏠
Working from home

Cenk Canarslan cenkc

🏠
Working from home
View GitHub Profile
@cenkc
cenkc / switch-jdks
Created January 12, 2019 22:25
Switching between JDKs on windows
//jdk8.bat
@echo off
set JAVA_HOME=D:\Java\jdk1.8.0_111
set PATH=%JAVA_HOME%\bin;%PATH%
echo Displaying Java Version
java -version
//jdk11.bat
@echo off
set JAVA_HOME=D:\Java\jdk-11.0.1
@cenkc
cenkc / common-application.properties
Created February 6, 2019 21:31
Common Spring Boot Properties
# https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html
# ===================================================================
# COMMON SPRING BOOT PROPERTIES
#
# This sample file is provided as a guideline. Do NOT copy it in its
# entirety to your own application. ^^^
# ===================================================================
@cenkc
cenkc / SpringDeveloper-Playlists.txt
Created February 6, 2019 21:35
Youtube SpringDeveloper Playlists
https://www.youtube.com/user/SpringSourceDev/playlists
Spring Boot
https://www.youtube.com/playlist?list=PLgGXSWYM2FpOa_FTla-x5Wd10dpmgrRC4
@cenkc
cenkc / Log4jWithoutPropFile.java
Created March 7, 2019 06:53
Log4j without properties file
import org.apache.log4j.*;
//below is the default conversion pattern
PatternLayout pl = new PatternLayout("%r [%t] %p %c %x - %m%n");
Appender appender = new FileAppender(pl, "D:\\tmp\\hede.txt", false);
BasicConfigurator.configure(appender);
/*
// For direct output to console, use configure without appender
// it uses default pattern which mentioned up above
https://en.wikipedia.org/wiki/NMEA_0183
A sample file produced by a Tripmate 850 GPS logger. This file was produced in Leixlip, County Kildare, Ireland. The record lasts two seconds.
$GPGGA,092750.000,5321.6802,N,00630.3372,W,1,8,1.03,61.7,M,55.2,M,,*76
$GPGSA,A,3,10,07,05,02,29,04,08,13,,,,,1.72,1.03,1.38*0A
$GPGSV,3,1,11,10,63,137,17,07,61,098,15,05,59,290,20,08,54,157,30*70
$GPGSV,3,2,11,02,39,223,19,13,28,070,17,26,23,252,,04,14,186,14*79
$GPGSV,3,3,11,29,09,301,24,16,09,020,,36,,,*76
$GPRMC,092750.000,A,5321.6802,N,00630.3372,W,0.02,31.66,280511,,,A*43
$GPGGA,092751.000,5321.6802,N,00630.3371,W,1,8,1.03,61.7,M,55.3,M,,*75
@cenkc
cenkc / mockito-multiple-calls-to-1method.txt
Created May 10, 2019 11:58
Mockito multiple calls to the same method
https://stackoverflow.com/questions/8088179/using-mockito-with-multiple-calls-to-the-same-method-with-the-same-arguments/8395685
@cenkc
cenkc / BeanUtil.java
Last active September 25, 2019 10:40
package com.cenkc.util;
import org.springframework.stereotype.Service;
import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.WebApplicationContext;
/**
* Created by Cenk Canarslan on 2019-09-06
*/
@Service
@cenkc
cenkc / StreamExamples.java
Last active September 8, 2019 21:05
Iteration with Streams API
// BigDecimal iterator 1 thru 10
Stream.iterate(
BigDecimal.ONE,
bigDecimal -> bigDecimal.add(BigDecimal.ONE)
)
.limit(10)
.forEach(System.out::println);
// Integer iterator 1 thru 10
Stream.iterate(1,n -> n + 1).limit(10).forEach(System.out::println);
@cenkc
cenkc / CaseInsensitiveRegexSearchAndReplace.java
Last active October 21, 2019 11:37
regex case-insensitive search
public static void main(String[] args) {
// regex case-insensitive search (?i:SOME_STRING)
String hede = "http://127.0.0.1:8888/SomeWS/SomeWSEndpointService?wSdL";
String hodo = hede.replaceFirst("(?i:\\?wsdl)", "?wsdl");
System.out.println("hede = " + hede);
System.out.println("hodo = " + hodo);
}
//hede = http://127.0.0.1:8888/SomeWS/SomeWSEndpointService?wSdL
//hodo = http://127.0.0.1:8888/SomeWS/SomeWSEndpointService?wsdl
@cenkc
cenkc / SomeStuff.java
Created December 10, 2019 18:17
remote debugging and command line parameter usage
/*
to run
/.../java/bin/java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=4423 -jar /tmp/some-test-0.0.1-SNAPSHOT.jar --xip=192.168.1.1 --xport=11111
*/
@Component
public class SomeWorker implements ApplicationRunner {
public static final Logger logger = LoggerFactory.getLogger(SomeWorker.class);
@Value("${xip}")