Skip to content

Instantly share code, notes, and snippets.

@mhewedy
mhewedy / FeignRetryable.java
Last active May 4, 2024 00:08
Annotation for feign retry
/**
* Enable retries on selected Feign methods.
* <p>
* <ol>
* <li>In the feign config class add:
* <pre>
* {@code
* @Bean
* public Retryer feignRetryer() {
@mhewedy
mhewedy / portforward
Last active March 15, 2024 15:16
create a proxy and do port forward on top of kubernetes/openshift
#!/bin/bash
doPortForward() {
ns=$1
ip=$2
port=$3
listen_port=`awk -F ':' '{print $1}' <<< "$port"`
container_port=`awk -F ':' '{print $2}' <<< "$port"`
container_port=${container_port:-$listen_port}
target_port=$4 || `shuf -i 2000-65000 -n 1`
@mhewedy
mhewedy / Lock.java
Last active January 13, 2024 16:56
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import java.time.Duration;
import java.util.function.Supplier;
/**
* A simple implementation for Distributed Lock based on Redis.
@mhewedy
mhewedy / DemoApplication.java
Last active November 15, 2023 08:53
Retriable RestTemplate
package com.example.demo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.boot.web.client.RestTemplateCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.retry.policy.SimpleRetryPolicy;
@mhewedy
mhewedy / RabbitMQConfig.java
Last active October 28, 2023 10:16
Load RabbitMQ definitions JSON file on startup
import brave.spring.rabbit.SpringRabbitTracing;
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 lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisKeyValueTemplate;
import org.springframework.stereotype.Service;
import javax.persistence.Id;
import java.time.Duration;
import java.time.Instant;
import java.util.Optional;
import java.util.function.Supplier;
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 / Main.kt
Last active February 14, 2023 15:10
Kotlin X509 certificate + PEM private key : encryption and decryption
/**
depends on config from https://www.baeldung.com/java-bouncy-castle
*/
import org.bouncycastle.cms.*
import org.bouncycastle.cms.jcajce.JceCMSContentEncryptorBuilder
import org.bouncycastle.cms.jcajce.JceKeyTransEnvelopedRecipient
import org.bouncycastle.cms.jcajce.JceKeyTransRecipientInfoGenerator
import org.bouncycastle.jce.provider.BouncyCastleProvider
import org.bouncycastle.util.encoders.Base64
@mhewedy
mhewedy / server.go
Created August 10, 2019 20:50
Example with custom authentication and authorization with echo go web framework
package main
import (
"fmt"
"github.com/dgrijalva/jwt-go"
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
"net/http"
"time"
)
@mhewedy
mhewedy / rpm_install
Last active October 28, 2022 08:20
Install RPM package (from the internet or from local filesystem) to a remote Linux machine (with no internet access)
#!/bin/bash
set -e
#set -x
if [ "$#" -ne 2 ];
then
echo "Usage: $0 <user@ip> [rpm url|file]"
exit
fi