Skip to content

Instantly share code, notes, and snippets.

@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`
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;
@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 / 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 / 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.*;
@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
@mhewedy
mhewedy / jmx_endpoint_invoker.sh
Last active June 17, 2022 07:24
invoke springboot jmx endpoints
#!/usr/lib/jvm/java/bin/java --source 17
/* example
jmx_endpoint_invoker.sh Health health
*/
import com.sun.tools.attach.AttachOperationFailedException;
import com.sun.tools.attach.VirtualMachine;
import com.sun.tools.attach.spi.AttachProvider;
@mhewedy
mhewedy / builtin_cd.sh
Created May 9, 2022 08:47
override the builtin function cd in .bashrc for wsl pathes to work automatically
#copy and paste in .bashrc and then: soruce .bashrc
# for windows pathes, you need to wrap it in double quotes
function cd() {
if [[ $@ == *"\\"* ]]; then
p=`wslpath "$@"`
builtin cd "$p"
else
builtin cd "$@"
fi
import socket
class RedisClient:
def __init__(self, **kwargs):
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sock.connect((kwargs['host'], kwargs['port']))
def subscribe(self, channel):
@mhewedy
mhewedy / scw
Last active March 24, 2022 12:04
#!/usr/bin/env python3
import subprocess
import sys
SCW_TYPE = 'DEV1-S'
SCW_ZONE = 'nl-ams-1'
SCW_IMAGE = 'centos_8'
SCW_PROJECT_ID = '<projectid>'
LOG_CMD = False