git config user name email

Use following command to add user name and email.

git enable color output

The default output of git is without color. Add following config in ~/.gitconfig can enable the git color output in your terminal. If there is not .gitconfig file create one.

Java8 Collectors.partitioningBy example

Collectors.partitioningBy is used to divide stream into two map. The key of two group are true and false. Two list of values are collections of elements that satisfy the condition. The example code is here.

Linux curl command examples

curl is a good tool to help you make a request. Before introducing how to use it we need to start a server which receives the requests. I use Spring Boot as a simple server. The code is like following.

Java8 stream groupingBy example

When we want to group the list data, we have to write some tedious code in the old version of the JDK. For example we want to group list of people by age. The code is like this before JDK8.

Commonly used vim configuration

Here is my own common vim configuration. Disable syntax and enable spell check in markdown file.

git auto push when commit

Add following function in your ~/.bashrc file then you can use one command to commit changes and push them to remote.

Java8 stream reduce example

reduce method of stream is used to calculate elements in the stream and get the result. For example, we can use reduce to get the sum of Integer list. It can also help you to get the min or max number of Integer list.

Java8 stream flatMap example

map method is used to handle the element of stream and output the stream. flatMap method is used to handle multiple stream and output new stream. Here is some easy examples.

Maven Java heap space OutOfMemoryError

When I run mvn clean install -DskipTests to build my project I got an error message. The content of message is like following.

Nginx set content type

Nginx will add Content-Type depend on suffix of url in response header. The suffix and Content-Type mapping are in /etc/nginx/mime.types. There are two ways to change Content-Type in Nginx.

Spring Boot specify location

When I run Spring Boot jar in different environment I need different configuration. I use command line to assign the location of Let's say you have a project without file and you package it as jar. You can use java -jar YOUR_PACKAGE_NAME.jar to start this project. The output is like following.

VirtualBox CentOS static ip address

I install CentOS in virtualBox and I use Bridged Networking to connect internet. Virtual machine is like a real machine in bridged networking mode. The problem is that when I restart virtual machine the ip will be changed. I have to use ssh to reconnect virtual machine(CentOS). To solve this problem I add another network adapter in virtual machine with Host only mode. Finally, I can connect virtual machine by static ip address.

Linux awk bigger or less than

Let's say you have a file which contains log content. awk command can help you split every line of it and print the field you care about. awk can do more than this. Let's say your log file might look like this.

Spring get next run time by cron expression

I always use cron expression to execute scheduling task. I want to know when the task will be executed. I use CronSequenceGenerator to calculate the next run time which is a class of Spring Framework. The example code is here.