Skip to content

Instantly share code, notes, and snippets.

package main
import (
    "fmt"
    "math/rand"
    "os"
    "os/signal"
    "time"
)
@mhewedy
mhewedy / MultiRabbitConfig.java
Last active September 17, 2022 10:15
Multi-rabbit config for spring amqp
import lombok.Data;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.MultiRabbitListenerAnnotationBeanPostProcessor;
import org.springframework.amqp.rabbit.annotation.RabbitListenerAnnotationBeanPostProcessor;
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
import org.springframework.amqp.rabbit.connection.*;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
public class SecurityConfig {
// ......
// userIds claim mapper should be added to keycloak that gets its value from user's attribute with the same name
@Bean
public JwtDecoder customDecoder(OAuth2ResourceServerProperties properties, HttpServletRequest httpServletRequest) {
NimbusJwtDecoder jwtDecoder = NimbusJwtDecoder.withJwkSetUri(
properties.getJwt().getJwkSetUri()).build();
@mhewedy
mhewedy / SkipMissingChangelogsSpringLiquibase.java
Last active September 17, 2022 11:35
SkipMissingChangelogsSpringLiquibase
import liquibase.changelog.IncludeAllFilter;
import liquibase.integration.spring.SpringLiquibase;
import liquibase.integration.spring.SpringResourceAccessor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.liquibase.LiquibaseProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ResourceLoader;
@mhewedy
mhewedy / Promise.java
Last active June 14, 2021 03:44
Retrofit Promise-like (with then/error funcs) Call Adapter
import android.os.Handler;
import android.os.Looper;
import com.google.gson.Gson;
import java.lang.annotation.Annotation;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.concurrent.Executor;
static {
disableSslVerification();
}
private static void disableSslVerification() {
try
{
// Create a trust manager that does not validate certificate chains
javax.net.ssl.TrustManager[] trustAllCerts = new javax.net.ssl.TrustManager[] {new javax.net.ssl.X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
@mhewedy
mhewedy / spring-data-jpa-mongodb-expressions.js
Created March 26, 2021 10:35
Create spring-data-jpa-mongodb-expressions in javascript
let lastName = "ibrahim";
let birthDate = "1981-01-03";
let q = {};
if (lastName) {
q.lastName = lastName;
}
if (birthDate) {
@mhewedy
mhewedy / configupdater.sh
Last active January 7, 2021 08:47
script to update spring boot apps configurations inside k8s/openshift
#!/usr/bin/env bash
ips=$(kubectl get ep myapp -o jsonpath='{range @}{.subsets[*].addresses[*].ip}{end}')
arr=($ips)
curls=""
for ip in "${arr[@]}"; do
curls="${curls}curl ${ip}:8080/actuator/refresh -d {} -H 'Content-Type: application/json' && "
done
@mhewedy
mhewedy / download_openjdk<version>.sh
Last active October 31, 2020 23:23
Download latest release of openjdk 15 from jdk.java.net
wget -O openjdk-15.tar.gz $(curl -s https://jdk.java.net/15/ | gawk 'match($0, "http.*openjdk-15.*linux-x64_bin.tar.gz", ary) {print ary[0]}' | uniq)
@mhewedy
mhewedy / k8s_alerting.sh
Created October 3, 2020 18:52
Report k8s jobs running for long time
# report jobs is running for more than 60 minutes
sudo kubectl get pods -l job-name -o jsonpath='{range .items[*]}{.metadata.name}{" "}{.status.phase}{" "}{.status.startTime}{"\n"}{end}' | while read line; do
name=$(echo $line | awk '{print $1}')
phase=$(echo $line | awk '{print $2}')
startTime=$(echo $line | awk '{print $3}')
now=$(date +%s)
start=$(date -d $startTime +"%s")
diff=$(( ($now - $start)/60 ))