Skip to content

Instantly share code, notes, and snippets.

@s-petit
s-petit / Jenkinsfile-release
Last active July 10, 2018 12:47
Perform a maven release via a Jenkins pipeline with declarative syntax
#!/usr/bin/env groovy
pipeline {
stages {
stage('Prepare') {
steps {
withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'YOUR_CREDENTIALS_ID', usernameVariable: 'GIT_USERNAME', passwordVariable: 'GIT_PASSWORD']]) {
sh 'mvn -B release:prepare -Dusername=$GIT_USERNAME -Dpassword=$GIT_PASSWORD'
}
}
@s-petit
s-petit / docker.md
Last active December 20, 2019 09:36
Docker useful commands

List all containers with its restart policy

docker inspect -f "{{.Name}} {{ .HostConfig.RestartPolicy }}" $(docker ps -a -q)

Remove all containers

docker rm $(docker ps -a -q) -f

by name pattern (ex: '-dev')

@s-petit
s-petit / alias.sh
Created July 10, 2018 12:38
Useful aliases
JAVA_HOME=$(readlink -f /usr/bin/javac | sed "s:/bin/javac::")
alias mci='mvn clean install -DskipTests'
alias mcp='mvn clean package -DskipTests'
alias jacoco='mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent verify org.jacoco:jacoco-maven-plugin:report'
alias zshconfig='subl ~/.zshrc'
alias j='fasd_cd -d'
alias netgrep='netstat -planet | grep $*'
alias dk='docker'
@s-petit
s-petit / jvm-monitoring.md
Created October 11, 2018 11:10
Monitoring JVM

Process en cours d’execution

jps -lvm

Connaitre les options d’une JVM en cours d’execution

jcmd VM.command_line

jcmd VM.flags

@s-petit
s-petit / new-bash.sh
Last active August 9, 2019 08:59
bash script bootstrap
#!/bin/bash
usage="$(basename "$0") [-h --help] [-v A_VALUE] -- bash script description
where:
-h or --help shows this help text"
optspec=":-:"
while getopts "$optspec" optchar; do
case "${OPTARG}" in
@s-petit
s-petit / hibernate-best-practices.md
Created November 29, 2018 15:19
Hibernate Best Practices

The goal of this gist is to apply Hibernate best practices for performance purposes:

  • Use Bidirectional OneToMany relations, with Sets instead of Lists
  • Transactions should be inside Services in order to combine several DAO calls inside the same transaction
  • Using read-only transactions in order to describe when transactions should be readonly. Moreover, it improves performance and prevents non desired writes
  • Mark read-only entities a @immutable
  • Implement equals and hashcode with business key inside entities, which is useful especially for OneToMany relations

Interesting reads:

@s-petit
s-petit / Dockerfile
Created December 4, 2018 09:02
Execute SQL instructions on an empty SQL Server during container initialization (inside Dockerfile)
FROM microsoft/mssql-server-linux
COPY sh-location/execute-sql.sh ./
ENTRYPOINT /opt/mssql/bin/sqlservr & ./execute-sql.sh; wait
HEALTHCHECK CMD /opt/mssql-tools/bin/sqlcmd -U sa -P TheP4sswd -d MyDatabase -Q "SELECT 1"
@s-petit
s-petit / mongo
Last active September 23, 2019 12:17
Mongo commands
### Dump a Mongo database
mongodump --host <HOST> --port <PORT> -d <DATABASE> -u <USER> -p <MDP> --gzip
### Restore a Mongo database
mongorestore -d <DATABASE> -u <USER> -p <MDP> --host <HOST> --dir <DUMP_LOCATION> --gzip
### drop all collections