Skip to content

Instantly share code, notes, and snippets.

View Genzer's full-sized avatar

Genzer Hawker Genzer

View GitHub Profile
@Genzer
Genzer / README.md
Last active June 27, 2025 07:52
A simple implementation of time-based nonce

Time-based nonce

This is a simple time-based nonce that you can used in various situations. The nonce is designed to be time-based so you can use it with a short lifetime (e.g. 5 or 10 seconds).

Design decisions

TimestampedNonce uses 192 bits with:

  • First 64 bits for the expiration timestamp, milliseconds since EPOCH.
  • The next 128 bits is for entropy. This is secure enough in this situation.
@Genzer
Genzer / MemoizeSupplier.java
Created June 13, 2025 11:42
An attempt to make a simpler implementation of cyclops.function.Memoize.memoizeSupplier (make it lazy)
import java.util.concurrent.atomic.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.stream.*;
import java.util.*;
import cyclops.function.*;
/**
* This class is my attempt to see if I can make an implementation of cyclops's Memoize.memoizeSupplier
* simpler without relying on `synchronize` keyword (as the actual implementation), or `ConcurrentHashMap#computeIfAbsent`
@Genzer
Genzer / no_body_leaves.slack-workflow.json
Created May 30, 2025 07:01
A simple Slack Workflow that adds member who leaves again.
{
"workflow": {
"title": "No Body Leaves",
"description": "Invite who ever leaves the channel again",
"icon": "",
"input_parameters": {
"Ft08U92KCRPH__user_id": {
"type": "slack#/types/user_id",
"name": "Ft08U92KCRPH__user_id",
"description": "The user who left the channel",

Mitigate "Rate Limiting bypass" through AWS ALB if the application relies on X-Forwarded-For

This gist documents a tactic which works in a situation:

  • Your Software System runs behind an AWS Application Load Balancer (ALB)
  • Your Software System uses AWS WAF in conjunction with ALB.
  • Your Software System handles Rate Limiting by itself.
  • Your Software System Rate Limiting implementation make use of X-Forwarded-For header to determine the correct Client Source IP.
@Genzer
Genzer / UuidShortener.java
Last active May 18, 2025 11:47
Shorten an UUIDv4 by encoding in Base64
import java.util.UUID;
import java.util.Base64;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
public class UuidShortener {
/* NOTE:
* The implementation was mostly copied from StackOverflow [1],
* as well as the hint of using BIG_ENDIAN [2].
@Genzer
Genzer / Loops.java
Last active June 24, 2025 23:51
Microbenchmarking using JBang and JMH
//DEPS org.openjdk.jmh:jmh-generator-annprocess:1.36
// --javaagent=ap-loader@maxandersen=start,event=cpu,file=profile.html
package com.grokhard.benchmarking;
import org.openjdk.jmh.*;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.infra.Blackhole;
import java.util.stream.*;
import java.util.*;
@Genzer
Genzer / DnsResolver.java
Last active November 29, 2024 08:50
DnsResolver.java
import java.util.*;
import java.util.stream.*;
import javax.naming.Context;
import javax.naming.NameNotFoundException;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.DirContext;
package com.grokhard.explorejavaconcurrency;
import static java.util.concurrent.TimeUnit.SECONDS;
import java.util.Objects;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
/**
#!/usr/bin/env bash
set -e -u -o pipefail
# Send, in sequential order, 10 requests and prints only the HTTP Status Code and the total time of the request
# with a Connnection Time Out in 5 seconds.
URL="$1"
{
for _ in {1..10};
do