Skip to content

Instantly share code, notes, and snippets.

View rbaul's full-sized avatar

Roman Baul rbaul

View GitHub Profile
@rbaul
rbaul / ReactDemo.java
Created April 21, 2024 11:07
React flux demo doOnNext and count
public class ReactDemo {
public static void main(String[] args) {
Flux.range(1,0)
.doOnNext(System.out::println)
.count().doOnNext(size -> {
if (size == 0) {
System.out.println("Size is: " + size);
}
}).subscribe();
@rbaul
rbaul / RestController.java
Last active June 29, 2023 09:43
MULTIPART_FORM_DATA_VALUE: Client (Python) - Server (Spring Boot)
@PostMapping(path = "/request-part/employee/object", consumes = { MediaType.MULTIPART_FORM_DATA_VALUE })
public Person requestPartObject(@RequestPart Person employee, @RequestPart MultipartFile document) {
return employee;
}
public record Person (String name, String address) {}
@rbaul
rbaul / RateLimitModel.java
Created May 15, 2023 06:37
RateLimit Model
package com.github.rbaul.rate_limit;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.util.CollectionUtils;
import java.util.HashMap;
@rbaul
rbaul / SpringBootEnv.java
Created September 7, 2022 10:53
Get all environment in Spring Boot Application
Map<String, Object> map = new HashMap();
for(Iterator it = ((AbstractEnvironment) env).getPropertySources().iterator(); it.hasNext(); ) {
PropertySource propertySource = (PropertySource) it.next();
if (propertySource instanceof MapPropertySource) {
map.putAll(((MapPropertySource) propertySource).getSource());
}
}
return map;
@rbaul
rbaul / Linux command
Last active February 1, 2022 08:51
Replace linux shell (ash, sh, bash)
/etc # cat passwd | grep "/bin/ash"
root:x:0:0:root:/root:/bin/ash
task-executor:x:1000:1000:Linux User,,,:/home/task-executor:/bin/ash
/etc # sed -i 's+/bin/ash+/bin/sh+g' passwd
/etc # cat passwd | grep "/bin/ash"
/etc # cat passwd | grep "/bin/sh"
root:x:0:0:root:/root:/bin/sh
task-executor:x:1000:1000:Linux User,,,:/home/task-executor:/bin/sh
@rbaul
rbaul / ArchiveUtils.java
Last active July 28, 2022 11:47
Read tar tar.gz in memory
/**
* Example of use
*/
public static void main(String[] args) throws IOException {
byte[] tarByte = Files.readAllBytes(Paths.get("some.tar.gz"));
String tar = Base64.getEncoder().encodeToString(tarByte);
}
@rbaul
rbaul / RabbitLIstener.java
Created January 6, 2022 20:04
Rabbit Listener configure arguments
@RabbitListener(bindings = @QueueBinding(
value = @Queue(value = "QUEE_NAME",
durable = "true",
arguments = {
@Argument(name = "x-single-active-consumer", value = "true", type = "java.lang.Boolean")
}
),
exchange = @Exchange(value = "EXCHANGE_NAME", type = ExchangeTypes.TOPIC),
key = {
"ROUTE_KEY_1",
@rbaul
rbaul / RabbitListenerConfiguration.java
Last active January 5, 2022 20:54
Configure default Rabbit Listener container with Jackson converter
public class RabbitListenerConfiguration {
@Autowired
public void rabbitListenerContainerFactory(
@Qualifier(RabbitListenerAnnotationBeanPostProcessor.DEFAULT_RABBIT_LISTENER_CONTAINER_FACTORY_BEAN_NAME) SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory,
ObjectMapper objectMapper) {
rabbitListenerContainerFactory.setMessageConverter(new Jackson2JsonMessageConverter(objectMapper));
}
}
@rbaul
rbaul / jlint.txt
Created November 17, 2021 07:04
jlink usage
C:\"Program Files"\AdoptOpenJDK\jdk-15.0.2.7-openj9\bin\jlink --module-path C:\"Program Files"\AdoptOpenJDK\jdk-15.0.2.7-openj9\jmods --verbose --add-modules java.base,java.logging,java.compiler,java.
scripting,java.xml,jdk.net,jdk.jdwp.agent,java.sql,jdk.unsupported,java.naming,java.desktop,java.management,java.security.jgss,java.instrument,jdk.management.agent,jdk.localedata,openj9.sharedclasses,jdk.naming.dns,jdk.jcmd,java.sql
.rowset,jdk.crypto.cryptoki,jdk.crypto.ec --output jdk-minimal
// Install
https://adoptopenjdk.net/releases.html?variant=openjdk15&jvmVariant=openj9
// Create new JDK
C:\"Program Files"\AdoptOpenJDK\jdk-15.0.2.7-openj9\bin\jlink --module-path C:\"Program Files"\AdoptOpenJDK\jdk-15.0.2.7-openj9\jmods --verbose --add-modules java.base,java.compiler,java.datatransfer,java.desktop,java.instrument,java.logging,java.management,java.management.rmi,java.naming,java.net.http,java.prefs,java.rmi,java.scripting,java.se,java.security.jgss,java.security.sasl,java.smartcardio,java.sql,java.sql.
@rbaul
rbaul / How to.txt
Created November 4, 2021 07:00
Configure gradle properties from environment variable
Instead of environment variables, like myProperty, please use Gradle properties
they can be specified in the gradle.properties file, if not secret.
For more vulnerable data or properties that may change when running tasks,
you can set such properties using environment variables prefixed with
ORG_GRADLE_PROJECT_
example: ORG_GRADLE_PROJECT_myProperty