Skip to content

Instantly share code, notes, and snippets.

@mhewedy
mhewedy / RabbitMQConfig.java
Created Nov 7, 2022
Load RabbitMQ definitions JSON file on startup
View RabbitMQConfig.java
import com.rabbitmq.client.Connection;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.camel.CamelContext;
import org.apache.camel.component.rabbitmq.RabbitMQEndpoint;
import org.apache.camel.component.rabbitmq.springboot.RabbitMQComponentConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.EventListener;
@mhewedy
mhewedy / rpm_install
Last active Oct 28, 2022
Install RPM package (from the internet or from local filesystem) to a remote Linux machine (with no internet access)
View rpm_install
#!/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 Jun 17, 2022
invoke springboot jmx endpoints
View jmx_endpoint_invoker.sh
#!/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
override the builtin function cd in .bashrc for wsl pathes to work automatically
View builtin_cd.sh
#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
View redis_subscribe.py
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):
View scw
#!/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
View nearest.go
package main
import (
    "fmt"
    "math/rand"
    "os"
    "os/signal"
    "time"
)
@mhewedy
mhewedy / MultiRabbitConfig.java
Last active Sep 17, 2022
Multi-rabbit config for spring amqp
View MultiRabbitConfig.java
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;
View SecurityConfig.java
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 Sep 17, 2022
SkipMissingChangelogsSpringLiquibase
View SkipMissingChangelogsSpringLiquibase.java
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;