Skip to content

Instantly share code, notes, and snippets.

View agrawald's full-sized avatar
🐌
I may be slow to respond.

Dheeraj (DJ) Agrawal agrawald

🐌
I may be slow to respond.
View GitHub Profile
@agrawald
agrawald / sibling-docker.md
Last active May 14, 2020 07:01
Spinning up sibling Docker containers from within a Docker container

Scenario

  • Node application which need redis to run functional test cases.
  • docker-compose is used to spin redis container as initial setup from within test case
  • have a docker-compose.yml file with redis service

dockerfile

FROM docker
@agrawald
agrawald / SIGINT.md
Last active February 26, 2024 14:44
Killing a process inside a docker container

Testing graceful shutdown of a docker container process

  • In order to log into a specific container in a bash shell you have to run following command

docker exec -ti <container id|name> bash

  • The above command will take u to the bash shell, now inside the bash shell search of the command which is running your application, for example, java or node

kill -2 $(pidof node)

  • The above command will kill the process node by sending SIGINT
@agrawald
agrawald / h2-jsonb.md
Created November 22, 2019 05:17 — forked from madz0/h2-jsonb.md
jsonb work around for H2 database

Creat a package-info file in the models package and put the following contents in there:

@org.hibernate.annotations.TypeDef(name = "jsonb", typeClass = JsonBinaryType.class)
package com.ourproject.model;

import com.vladmihalcea.hibernate.type.json.JsonBinaryType;

I used JsonBinaryType in hibernate-types-52 library.

Then in the entity class, I removed columnDefinition="jsonb" from the @Column and only used @Type(type = "jsonb")

@agrawald
agrawald / config.java
Created August 28, 2019 00:41
Spring-boot: RestTemplate: Reading Response Body multiple times
@Bean
public RestTemplate restTemplate(final LauHeaderInterceptor lauHeaderInterceptor) {
final RestTemplate restTemplate = new RestTemplate();
restTemplate.setMessageConverters(Collections.singletonList(new MappingJackson2HttpMessageConverter()));
restTemplate.setErrorHandler(new ResponseErrorHandler() {
@Override
public boolean hasError(final ClientHttpResponse response) throws IOException {
return false;
}
@agrawald
agrawald / gist:a6ee36831c69de473fdde93c617ff029
Created July 23, 2019 02:58 — forked from mtigas/gist:952344
Mini tutorial for configuring client-side SSL certificates.

Client-side SSL

For excessively paranoid client authentication.


Updated Apr 5 2019:

because this is a gist from 2011 that people stumble into and maybe you should AES instead of 3DES in the year of our lord 2019.

some other notes:

@agrawald
agrawald / build.gradle
Created July 4, 2019 04:07
Java POJO from JSON Schema using gradle
apply plugin: 'jsonschema2pojo'
// Each configuration is set to the default value
jsonSchema2Pojo {
// Whether to generate builder-style methods of the form withXxx(value) (that return this),
// alongside the standard, void-return setters.
generateBuilders = true
// Location of the JSON Schema file(s). This may refer to a single file or a directory of files.
source = files("${sourceSets.main.output.resourcesDir}/schema")
@agrawald
agrawald / winsw.xml
Created July 4, 2019 04:02
WINSW: How to deploy spring-boot application as windows service
<service>
<id>gpb-swift-tracker-bridge</id>
<name>GpbSwiftTrackerBridge</name>
<description>This runs Spring Boot as a Service.</description>
<executable>java</executable>
<arguments>-Xmx256m -jar "gpb-swift-tracker-bridge.jar" --server.port=9192 --spring-config-location=file://C://properties/gpb-swift-tracker-bridge.yaml</arguments>
<logmode>rotate</logmode>
<onfailure action="restart" delay="10 sec"/>
</service>
5097de91d0846c5973878740dc6982d377cc48930bd9612e06703ea6e72bc1728e86f9607d748ca8066023860b95b05f5cbdba6efcaf58dfae49afc9f9d2917b
@agrawald
agrawald / Jenkinsfile
Created May 21, 2018 02:05 — forked from jonico/Jenkinsfile
Example for a full blown Jenkins pipeline script with multiple stages, input steps, injected credentials, heroku deploy, sonarqube and artifactory integration, multiple Git commit statuses, PR merge vs branch build detection, REST API calls to GitHub deployment API, stage timeouts, stage concurrency constraints, ...
#!groovy
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
/*
Please make sure to add the following environment variables:
HEROKU_PREVIEW=<your heroku preview app>
HEROKU_PREPRODUCTION=<your heroku pre-production app>
HEROKU_PRODUCTION=<your heroku production app>
@agrawald
agrawald / SSLPoke.java
Created August 18, 2017 14:50 — forked from 4ndrej/SSLPoke.java
Test of java SSL / keystore / cert setup. Check the commet #1 for howto.
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import java.io.*;
/** Establish a SSL connection to a host and port, writes a byte and
* prints the response. See
* http://confluence.atlassian.com/display/JIRA/Connecting+to+SSL+services
*/
public class SSLPoke {
public static void main(String[] args) {