Skip to content

Instantly share code, notes, and snippets.

View thomasdarimont's full-sized avatar
🏠
Working from home

Thomas Darimont thomasdarimont

🏠
Working from home
View GitHub Profile
@aelkz
aelkz / [FEDORA] gitkraken
Last active November 14, 2023 05:50
How to install gitkraken on Fedora [25,26,27] + launcher icon
#!/bin/bash
# Download GitKraken
wget https://release.gitkraken.com/linux/gitkraken-amd64.tar.gz
# copy the downloaded file into /opt directory
cp gitkraken-amd64.tar.gz /opt/
cd /opt

Scaling your API with rate limiters

The following are examples of the four types rate limiters discussed in the accompanying blog post. In the examples below I've used pseudocode-like Ruby, so if you're unfamiliar with Ruby you should be able to easily translate this approach to other languages. Complete examples in Ruby are also provided later in this gist.

In most cases you'll want all these examples to be classes, but I've used simple functions here to keep the code samples brief.

Request rate limiter

This uses a basic token bucket algorithm and relies on the fact that Redis scripts execute atomically. No other operations can run between fetching the count and writing the new count.

@thomasdarimont
thomasdarimont / KeycloakClientAuthExample.java
Last active June 30, 2025 01:39
Retrieve and verify AccessToken with Keycloak Client.
package de.tdlabs.keycloak.client;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.keycloak.OAuth2Constants;
import org.keycloak.RSATokenVerifier;
import org.keycloak.admin.client.Keycloak;
import org.keycloak.admin.client.KeycloakBuilder;
import org.keycloak.common.VerificationException;
import org.keycloak.jose.jws.JWSHeader;
import org.keycloak.representations.AccessToken;
@sts
sts / openidc_otp_validation.sh
Last active January 16, 2025 03:55
Keycloak OTP Validation API
BASE_URL=https://localhost:8081/auth
CLIENT_ID=curl-test
CLIENT_SECRET=
USERNAME=
PASSWORD=
REALM=validation-test
OTP_CODE=027253
# OpenID Access Token via "Resource Owner Password Credentials Grant"
@odrotbohm
odrotbohm / MyBenchmark.java
Last active November 28, 2016 12:38
Benchmark showing differences between formatting JDK 8 dates and legacy Date instances
package org.sample;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.TimeZone;
import org.openjdk.jmh.annotations.Benchmark;
@AdamBien
AdamBien / 31stAirhacksQ&A.md
Last active October 3, 2016 09:58
31stAirhacksQ&A.md
@joschi
joschi / graylog_token.txt
Last active September 28, 2023 04:27
Graylog access token login
# Create an access token for user "admin" with name "test-1234"
# POST /users/{username}/tokens/{name}
$ curl -i -u admin:admin -H 'Accept: application/json' -X POST 'http://127.0.0.1:12900/users/admin/tokens/test-1234?pretty=true'
HTTP/1.1 200 OK
X-Graylog-Node-ID: cd03ee44-b2a7-4824-be16-bb7456149dbd
Content-Type: application/json
Date: Mon, 08 Aug 2016 12:12:09 GMT
Content-Length: 139
{
@nipafx
nipafx / PackagePrivate.java
Created May 11, 2016 21:34
Demonstrating Visibility
package org.codefx.lab.visibility;
class PackagePrivate {
public String publicToUpper(String s) {
return s.toUpperCase();
}
String packageToUpper(String s) {
return s.toUpperCase();
@thomasdarimont
thomasdarimont / readme.md
Last active August 31, 2021 14:13
Use Keycloak as Identity provider for Drupal
@thomasdarimont
thomasdarimont / Java9Changes.java
Last active January 2, 2016 12:32
Quick ugly hack.. to diff Java 8 vs. Java 9 Runtime to find newly introduced Types / Methods.
package training;
import jdk.internal.jimage.ImageLocation;
import jdk.internal.jimage.ImageReader;
import jdk.internal.jimage.ImageReaderFactory;
import org.objectweb.asm.*;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;