Skip to content

Instantly share code, notes, and snippets.

View Eng-Fouad's full-sized avatar

Fouad Almalki Eng-Fouad

View GitHub Profile
@Eng-Fouad
Eng-Fouad / UrlSigner.java
Created October 14, 2024 01:34
Sign Minio/AWS S3 url manually in Java without dependencies
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
@Eng-Fouad
Eng-Fouad / CoreConfigs.java
Last active October 14, 2024 01:27
Print buildTimestamp at startup using Quarkus and Gradle
import io.smallrye.config.ConfigMapping;
/**
* Core configuration properties.
*
* @author Fouad Almalki
*/
@ConfigMapping(prefix = "core")
public interface CoreConfigs {
String buildTimestamp();
@Eng-Fouad
Eng-Fouad / Dockerfile
Last active August 28, 2023 03:24
Spring Boot Native with Mandrel
# Based on RedHat OS
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.8-1037
# Variables
ARG JAVA_VERSION=20
ARG MANDREL_VERSION=23.0.1.2-Final
ARG MANDREL_ARCH=amd64
ARG MANDREL_FILE_NAME=mandrel-java$JAVA_VERSION-linux-$MANDREL_ARCH-$MANDREL_VERSION.tar.gz
ARG MANDREL_URL=https://github.com/MANDREL/mandrel/releases/download/mandrel-$MANDREL_VERSION/$MANDREL_FILE_NAME
@Eng-Fouad
Eng-Fouad / db-versioning-strategy.md
Last active January 12, 2023 23:46
Database Versioning Strategy

SQL Folder Structure Example:

./src/main/sql
|___ deprecated/
|              |___ postgres/
|                           |___ v2/
|                                  |___ ddl.sql (contains CREATE TABLE statements)
|                                  |___ dml.sql (contains INSERT INTO statements)
|                                  |___ test-data.sql (contains INSERT INTO statements)

|___ latest/

@Eng-Fouad
Eng-Fouad / UserDao.java
Last active November 14, 2024 03:47
Using JDBI in Quarkus (native mode) [JDBI 3.38.2]
package io.fouad.demo.db;
public interface UserDao {
@SqlUpdate("CREATE TABLE user (id INTEGER PRIMARY KEY, name VARCHAR)")
void createTable();
@SqlUpdate("INSERT INTO user(id, name) VALUES (?, ?)")
void insertPositional(int id, String name);
@SqlUpdate("INSERT INTO user(id, name) VALUES (:id, :name)")
@Eng-Fouad
Eng-Fouad / SampleMingw.kt
Created July 9, 2019 22:38
Kotlin Native Win32 GUI Sample
package sample
import kotlinx.cinterop.*
import platform.windows.*
@ExperimentalUnsignedTypes
fun WndProc(hwnd: HWND?, msg: UINT, wParam: WPARAM, lParam: LPARAM) : LRESULT
{
// This switch block differentiates between the message type that could have been received. If you want to
// handle a specific type of message in your application, just define it in this block.
@Eng-Fouad
Eng-Fouad / Dockerfile
Created February 16, 2019 11:40
Dockerfile Example
FROM ubuntu:18.10
# install latest updates
RUN apt-get update && apt-get upgrade -y && apt-get dist-upgrade -y && apt-get autoremove -y && apt-get autoclean -y
# install unzip & wget
RUN apt-get install -y unzip wget
# install OpenJDK JRE
RUN apt-get install -y openjdk-11-jre
@Eng-Fouad
Eng-Fouad / server.xml
Created August 3, 2018 13:23
typical wlp server.xml
<?xml version="1.0" encoding="UTF-8"?>
<server description="new server">
<featureManager>
<feature>transportSecurity-1.0</feature>
<feature>jaxrs-2.1</feature>
<feature>jpa-2.2</feature>
<feature>cdi-2.0</feature>
</featureManager>
@Eng-Fouad
Eng-Fouad / javafx-combo-box-auto-completion.md
Last active June 15, 2020 02:49
JavaFX 8 ComboBox with Auto-Completion Support
@Eng-Fouad
Eng-Fouad / java.md
Created August 29, 2017 01:33
Generating ECPrivateKey and ECPublicKey

Generate keys:

KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC");
kpg.initialize(new ECGenParameterSpec("secp521r1"), new SecureRandom());
KeyPair keyPair = kpg.generateKeyPair();
ECPrivateKey privateKey = (ECPrivateKey) keyPair.getPrivate();
ECPublicKey publicKey = (ECPublicKey) keyPair.getPublic();
byte[] privateKeyS = privateKey.getS().toByteArray();
byte[] publicKeyX = publicKey.getW().getAffineX().toByteArray();

byte[] publicKeyY = publicKey.getW().getAffineY().toByteArray();