Skip to content

Instantly share code, notes, and snippets.

View dariahervieux's full-sized avatar

Daria dariahervieux

View GitHub Profile
@dariahervieux
dariahervieux / Problem.java
Created March 21, 2019 10:57
Spring MVC: return a RFC7807 problem object for Spring controller exception
package fr.da_sha1.exceptions;
//... imports are skipped for simplicity
/**
* Model class to send error details to a client in a form of a Problem details object, described in RFC7807.
* Inspired * by <a href="https://github.com/zalando/problem">zalando/problem</a> library.
* For more information please refer to https://tools.ietf.org/html/rfc7807
* @author Daria HERVIEUX
*/
@dariahervieux
dariahervieux / URLCreator.java
Last active October 20, 2020 15:25
Creating URL from strings: absolute and realtive URLS
import java.net.URL;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.MalformedURLException;
public class URLCreator {
public static void main(String[ ] args) throws MalformedURLException, URISyntaxException {
//base URL
URL urlPlateform = new URL("http://somehost.com/context");
@dariahervieux
dariahervieux / ValueObject1.java
Created November 23, 2020 09:05
Spring-Jackson: deserialize a "value"(immutable) object
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import lombok.*;
/**
* Value object with final fields,modified by @Value lombock annotation.
* Jackson will deserialize the object using the builder, generated by @Builder lombock annotation.
*/
@Value
@Builder
@JsonDeserialize(builder = ValueObject1.ValueObject1Builder.class)
public class ValueObject1 {
@dariahervieux
dariahervieux / UserTest.java
Created December 2, 2020 13:43
Testing temporal values with AssertJ (within)
import static org.assertj.core.api.Assertions.within;
//...
public class UserTest {
private UserService userService = new UserService();
@Test
public void given_valid_inputs_creation_is_ok() throws Exception {
User userToCreate = new User("name");
User user = userService.create(userToCreate);
@dariahervieux
dariahervieux / SslConfiguration.java
Created December 22, 2020 09:05
Java - Spring - SSL configuration: proxy, custom trust store
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.util.StringUtils;
import javax.annotation.PostConstruct;
import java.io.File;
import java.io.InputStream;
import java.nio.file.Files;
@dariahervieux
dariahervieux / git-cheat-sheet.md
Last active March 21, 2023 10:55
Git cheat-cheet

Lines endings

Windows - CRLF - carriage retur + linefeed - \r\n Linux - LF - linefeed - \n MAC - CR - carriage return - \r

Global configuration on working machine

core.autocrlf configuration setting:

  • true - this converts LF endings into CRLF when you check out code, converts CRLF line endings into LF when you add a file to the index; usually used on windows machines
  • input - this converts CRLF to LF on commit only; used on Linux machines; if a file with CRLF endings accidentally gets introduced, it gets fixed on commit
@dariahervieux
dariahervieux / gradle-cheat-sheet.md
Last active March 3, 2021 13:16
Gradle cheat-sheet

Generate a new project

You can use Build Init Plugin to generate a new Gradle build.

Generate a multi-module project

The java-application generates a new multi-module project with one submodule app. The henerated project has the following layout:

.
@dariahervieux
dariahervieux / linux-cmd-cheat-sheet.md
Last active November 5, 2023 10:26
Cheat-cheet: Linux useful commands

Linux Cheat-sheet

OS Details

Get distribution details:

$ cat /etc/*-release

Disk usage

@dariahervieux
dariahervieux / docker-cheat-sheet.md
Last active November 19, 2023 22:04
Docker cheat/tip sheet

Running container

Images

Get images information

Get image size: >docker images --format "table {{.ID}}\t{{.Tag}}\t{{.Size}}"

Inspect

@dariahervieux
dariahervieux / gitlab-runner-cheat-sheet.md
Created October 18, 2021 15:22
GitLab runners cheat/tip sheet

Docker executor

The Docker executor when used with GitLab CI, connects to Docker Engine and runs each build in a separate and isolated container. The image for the job is :

  • either the predefined image set up in the runner configuration (config.toml)
  • or the image set up in .gitlab-ci.yml

Using docker commands in jobs

Using docker on CICD jobs in GitLab means using Docker-in-Docker (dind):