Skip to content

Instantly share code, notes, and snippets.

View lovejavaee's full-sized avatar
👋
Java | C++ | Python | ML | DL

Jeff M lovejavaee

👋
Java | C++ | Python | ML | DL
View GitHub Profile
-Xmx10g
m2.xlarge (4 virtual cores)
Both Jetty and Netty execute the same code--generate 8k of random bits and compute a sha1, returning it over the wire.
INTERNAL (Benchmark tool runs on same machine)
--------
Jetty:
https://raw.githubusercontent.com/wso2/code-quality-tools/master/checkstyle/checkstyle.xml
After installing it, Restart the IDEA. Then go to File -> Settings -> Other Settings -> Checkstyle. Click positive mark to add a new configuration file. Select “Check style file accessible via HTTP” option and add https://raw.githubusercontent.com/wso2/code-quality-tools/master/checkstyle/checkstyle.xml URL.
@lovejavaee
lovejavaee / CacheConfig.java
Last active March 8, 2018 09:33
Guava cache with spring boot and clear cache method
import com.google.common.cache.CacheBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.CachingConfigurer;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.guava.GuavaCache;
import org.springframework.cache.interceptor.CacheErrorHandler;
import org.springframework.cache.interceptor.CacheResolver;
import org.springframework.cache.interceptor.KeyGenerator;
Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.
_____________________________________
## General rules
1. Follow standard conventions.
2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
3. Boy scout rule. Leave the campground cleaner than you found it.
4. Always find root cause. Always look for the root cause of a problem.
## Design rules
@lovejavaee
lovejavaee / git-hist.sh
Created February 13, 2018 07:18
git-hist.sh
##
# Creates an alias called "git hist" that outputs a nicely formatted git log.
# Usage is just like "git log"
# Examples:
# git hist
# git hist -5
# git hist <branch_name>
# git hist <tag_name> -10
##
git config --global alias.hist "log --pretty=format:'%C(yellow)[%ad]%C(reset) %C(green)[%h]%C(reset) | %C(red)%s %C(bold red){{%an}}%C(reset) %C(blue)%d%C(reset)' --graph --date=short"
By default surefire configuration includes tests matching "/Test*.java", "/_Test.java" or "/_TestCase.java" pattern.
By default failsafe configuration includes tests matching "/IT*.java", "/_IT.java" or "/_ITCase.java" pattern.
Usage:
mvn install -DskipUTs : Skips Unit tests
mvn install -DskipITs : Skips Integration tests
mvn install -DskipTests : Skips both Unit and Integration Tests
There is no doubt about the need for automated tests.
They
assure refactoring steps
help to detect weaknesses in the implementation
document the implemented logic
enable the implementation of modules, even if some basic modules are still missing (mocking)
Basically tests consist of 3 steps: Arrange, Act and Assert. That means establishing the test environment (Arrange), executing the logic (Act) and verifying the expectation (Assert).
Consider a bank account with the possibility to deposit money as a simple example. The implementation in advance:
@lovejavaee
lovejavaee / CustomResponseEntityExceptionHandler.java
Created July 24, 2017 09:03 — forked from matsev/CustomResponseEntityExceptionHandler.java
Generic response error handling using @ControllerAdvice
@ControllerAdvice
public class CustomResponseEntityExceptionHandler extends ResponseEntityExceptionHandler {
@Override
protected ResponseEntity<Object> handleMethodArgumentNotValid(MethodArgumentNotValidException ex, HttpHeaders headers, HttpStatus status, WebRequest request) {
List<FieldError> fieldErrors = ex.getBindingResult().getFieldErrors();
List<ObjectError> globalErrors = ex.getBindingResult().getGlobalErrors();
List<String> errors = new ArrayList<>(fieldErrors.size() + globalErrors.size());
String error;
for (FieldError fieldError : fieldErrors) {
#!/usr/bin/env python
from __future__ import print_function
import ansible.executor.task_queue_manager
import ansible.inventory
import ansible.parsing.dataloader
import ansible.playbook.play
import ansible.plugins.callback
import ansible.vars
@lovejavaee
lovejavaee / install-docker-compose.sh
Created May 10, 2017 04:01 — forked from daspecster/install-docker-compose.sh
Centos 7 docker compose install from scratch
#!/bin/bash
sudo yum update -y
sudo yum install -y netstat git rubygems gcc kernel-devel make perl
sudo yum install -y java-1.8.0-openjdk java-1.8.0-openjdk-devel maven
sudo gem install sass
cd /tmp