Skip to content

Instantly share code, notes, and snippets.

View DanielHons's full-sized avatar

Daniel Hons DanielHons

View GitHub Profile
@DanielHons
DanielHons / exponential-backoff.sql
Created August 20, 2020 21:26
Exponential backoff with postgreSQL
/*
Given a table containing at least a column for the number of errors (with no success in between) and
frequently calling the following select will provide the candidates for a retry using an exponential backoff.
*/
SELECT * FROM retryable_error WHERE
CURRENT_TIMESTAMP > (last_retry + CAST(CONCAT(CAST(POWER(2, error_count) AS text), 's') AS INTERVAL))
@DanielHons
DanielHons / OverlapTest.java
Created May 19, 2020 12:20
One-liner to compare time ranges for overlapping
package io.myplant.maintenanceevents.server.validation;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.junit.Test;
import java.sql.Time;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;