Skip to content

Instantly share code, notes, and snippets.

View asvanberg's full-sized avatar

Andreas Svanberg asvanberg

  • Stockholm, Sweden
View GitHub Profile
@asvanberg
asvanberg / SomeTest.java
Created September 7, 2024 21:44
Solving the problem of emptying the database between each test when using Spring Boot and Testcontainers
/*
This showcases how to use a Testcontainers provided database to test a Spring
Boot application while isolating every test so that changes to the database
does not interfere with other tests.
It accomplishes this without any reliance on implementation details to empty
out specific tables or anything else. There is no global "rollback only"
transaction semantics. You can run assertions against the actual data in the
database if desired, including any schema changes.
@asvanberg
asvanberg / broker.js
Last active February 8, 2023 12:36
Automatic stock market trader for Cookie Clicker
return (function () {
// Price must be this percentage of resting value to buy during slow climb
const slowClimbBuyThreshhold = 0.50;
// Sell when stable this close to market ceiling
const stableSellThreshhold = 0.96;
// Price must be this percentage of resting value to buy during fast climb
const fastClimbBuyThreshhold = 100.0;
const numberFormat = new Intl.NumberFormat([], { 'style': 'currency', 'currency': 'USD' });
@asvanberg
asvanberg / WebPush.java
Last active August 31, 2022 13:41
WebPush flow from start to finish (RFC 8291 & RFC 8188 (without the record chunking part over HTTP))
package io.github.asvanberg.http.webpush;
import javax.crypto.Cipher;
import javax.crypto.KeyAgreement;
import javax.crypto.Mac;
import javax.crypto.spec.GCMParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.nio.ByteBuffer;
import java.security.GeneralSecurityException;
import java.security.KeyPair;

Zipkin query optimization

Test setup

  • MariaDB (10.1.23-MariaDB-9+deb9u1)
  • Virtual server (2.5Ghz single core, 3GB RAM)
  • 701,241 spans
  • 3,508,959 annotations

Queries

@asvanberg
asvanberg / gist:64865561fc8d20ed00ecea8b39b86fb2
Created August 28, 2017 14:44
zipkin query optimization
-- original
SELECT DISTINCT
`zipkin_spans`.`trace_id_high`,
`zipkin_spans`.`trace_id`,
MAX(`zipkin_spans`.`start_ts`)
FROM
`zipkin_spans`
JOIN
`zipkin_annotations` ON (`zipkin_spans`.`trace_id_high` = `zipkin_annotations`.`trace_id_high`
AND `zipkin_spans`.`trace_id` = `zipkin_annotations`.`trace_id`
@asvanberg
asvanberg / build.sbt
Created September 26, 2015 22:55
Concatenate .coffee files before compiling to .js
lazy val concatCoffeeScript = taskKey[Seq[File]]("Concatenate .coffee")
lazy val concatCoffeeScriptFiles = settingKey[Seq[(String, Seq[String])]]("Files to concatenate, in order")
concatCoffeeScriptFiles := Seq(
"javascripts/app.coffee" Seq("javascripts/product.coffee", "javascripts/person.coffee", "javascripts/main.coffee")
)
concatCoffeeScript <<= (sourceDirectory in Assets, concatCoffeeScriptFiles, WebKeys.webTarget) map { (d, fs, t)
fs map { case (concatenated, parts)
val cf = t / concatenated