Posts

How to convert UTC Date Time String to Java object and compare it ?

Use java.time.Instant ; import java.time.Instant; Instant instantStart = Instant.parse("20200229T12:00:00Z"); Instant instantEnd = Instant.parse("20200329T12:00:00Z"); Instant instantNow = Instant.now(); return instantNow.isAfter(instantStart) && instantNow.isBefore(instantEnd);

Favourite VIM plugin, Mark : Highlight several words in different colours simultaneously.

Image
my favourite best best best vim plugin mark install vim mark *.vmb.gz :so % dependence ingo install vim ingo-library*.vmb.gz :so % Usage \m

How to convert json array to java Object

Use com.amazonaws.util.json.Jackson import com.amazonaws.util.json.Jackson; import java.util.ArrayList; import lombok.Data; @Data class DeviceList { private ArrayList<String> devices; } DeviceList deviceList = Jackson.fromJsonString( "{\"devices\":[\"Mobile\", \"Desktop\"]}", DeviceList.class);

Java Spring Bean constructor how to get call stack, backtrace

Easy wasy to print Java call stack or backtrace: Implement a function and throw an Exception. Call the function in the place you want to know its backtrace or callstack And Catch the Exception then Call Exception.getStackTrace class MyService { public static void f() throws Exception { throw new Exception(); } void forTest() { try { f(); } catch (Exception e) { e.printStackTrace(); } } } Via this solution, we can get Bean constructor call stack easily. [tomcat:launchProperties] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [tomcat:launchProperties] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) [tomcat:launchProperties] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [tomcat:launchProperties] at java.lang.reflect.Method.invoke(Method.java:498) [tomcat:launchProperties] at org.sprin

How to use @Mock @InjectMocks

class MyService { private UserDao userDao; } import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.mockito.runners.MockitoJUnitRunner; public class MyServiceTest { @InjectMocks private MyService myService; @Mock private UserDao userDao; @Before public void setUp() { myService = new MyService(); } } Cannot mock/spy class java.lang.String Mockito cannot mock/spy following: - final classes - anonymous classes - primitive types org.mockito.exceptions.base.MockitoException: Cannot mock/spy class java.lang.String Mockito cannot mock/spy following: - final classes - anonymous classes - primitive types at org.mockito.internal.runners.JUnit45AndHigherRunnerImpl$1.withBefores(JUnit45AndHigherRunnerImpl.java:27) at org.mockito.internal.runners.JUnit45AndHigher

How to increase terminal window buffer in IntelliJ

Image
Command + Shift + A or Ctrl + Shift + A Type registry, click "Registry..." Increase the "terminal.buffer.max.lines.count" to 100000 or any number you want, the default is 1000.

make vim like source insight, a effective c/c++ ide

Image
IDE setup latest vim git clone https://github.com/vim/vim.git cd vim/src ./configure --enable-cscope --enable-terminal make sudo make install https://www.vim.org/git.php use universal ctags git clone https://github.com/universal-ctags/ctags.git cd ctags ./autogen.sh ./configure make sudo make instahttps://www.tamacom.com/global/global-6.6.3.tar.gzll setup gnu tags wget https://www.tamacom.com/global/global-6.6.3.tar.gz tar -xvf global-6.6.3.tar.gz cd global-6.6.3 sh reconf.sh sudo apt install ncurses-dev ./configure --with-universal-ctags=/usr/local/bin/ctags make sudo make install https://www.tamacom.com/global/global-6.6.3.tar.gz http://www.gnu.org/software/global/download.html install gtags as vim plugin cp gtags.vim ~/.vim/plugin/ cp gtags-cscope.vim ~/.vim/plugin/ config gtags as cscope in ~/.vimrc " gtags configure " To use the default key/mouse mapping: let GtagsCscope_Auto_Map = 1 " To ignore letter case when searching: let GtagsCscope_Ignore_Cas