Skip to content

Instantly share code, notes, and snippets.

@omidp
omidp / java11SSLUtilities
Created May 4, 2021 03:57
java11SSLUtilities
import java.security.GeneralSecurityException;
import java.security.SecureRandom;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
import com.hazelcast.core.HazelcastInstance;
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
/**
* {@link HealthIndicator} for Hazelcast.
@omidp
omidp / DBTestConfig.java
Last active April 8, 2022 04:44
Spring integration test
import java.util.HashMap;
import java.util.Map;
import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.annotation.Bean;
SELECT *
FROM OPENDATA
WHERE other_tags IS NOT JSON;
create search index table_log_idx on tbl_lg (jsoncolumn) for json;
alter table table_log_idx add constraint ensure_json check (jsoncolumn is json)
@omidp
omidp / helper
Last active April 8, 2021 08:11
sprint resttemplate with redirect
protected static HttpClientBuilder getClientBuilder(boolean skipSslValidation) {
HttpClientBuilder builder = HttpClients.custom()
.useSystemProperties()
.setRedirectStrategy(new DefaultRedirectStrategy());
if (skipSslValidation) {
builder.setSslcontext(getNonValidatingSslContext());
builder.setSSLHostnameVerifier(new NoopHostnameVerifier());
}
builder.setConnectionReuseStrategy(NoConnectionReuseStrategy.INSTANCE);
return builder;
@omidp
omidp / SilentObjectCreator
Last active April 7, 2021 13:33
instantiate without calling constructor
import sun.reflect.ReflectionFactory;
import java.lang.reflect.Constructor;
public class SilentObjectCreator {
public static <T> T create(Class<T> clazz) {
return create(clazz, Object.class);
}
public static <T> T create(Class<T> clazz,
Class<? super T> parent) {
@omidp
omidp / Notepad++ add to every line
Created February 15, 2021 08:46
Notepad++ add to every line
https://stackoverflow.com/questions/11003761/notepad-add-to-every-line
Follow these steps:
Press Ctrl+H to bring up the Find/Replace Dialog.
Choose the Regular expression option near the bottom of the dialog.
To add a word, such as test, at the beginning of each line:
Type ^ in the Find what textbox
@omidp
omidp / gist:3b11b385487a07b46747c381e96a045e
Created February 13, 2021 06:06
postgresql table size
SELECT
relname AS "relation",
pg_size_pretty (
pg_total_relation_size (C .oid)
) AS "total_size"
FROM
pg_class C
LEFT JOIN pg_namespace N ON (N.oid = C .relnamespace)
WHERE
nspname NOT IN (
@omidp
omidp / generatecsr
Created January 17, 2021 07:43
generate csr
keytool -genkey -alias server -keyalg RSA -keysize 2048 -keystore yourdomain.jks
keytool -certreq -alias server -keyalg RSA -file yourdomain.csr -keystore yourdomain.jks
public BigDecimal multiply()
{
try
{
return new BigDecimal(new DecimalFormat("#.##").format(n1.multiply(n2)));
}
catch (ArithmeticException se)
{
MathContext mc = new MathContext(2, RoundingMode.HALF_UP);
return n1.multiply(n2, mc);