Skip to content

Instantly share code, notes, and snippets.

View swankjesse's full-sized avatar
🍩
busy busy

Jesse Wilson swankjesse

🍩
busy busy
View GitHub Profile
@swankjesse
swankjesse / HostSelectionInterceptor.java
Last active June 4, 2026 23:00
This OkHttp application interceptor will replace the destination hostname in the request URL.
import java.io.IOException;
import okhttp3.HttpUrl;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
/** An interceptor that allows runtime changes to the URL hostname. */
public final class HostSelectionInterceptor implements Interceptor {
private volatile String host;
/*
* Copyright (C) 2014 Square, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Calico</title>
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1">
<meta name="theme-color" content="#666666">
<meta property="og:image" content="https://rounds.app/game/8wrmh1kk80rk0hz635gscpare/og-image.png">
@swankjesse
swankjesse / QuotePreservingCookieJar.java
Created October 4, 2016 00:57
Like our JavaNetCookieJar, but preserve quote characters.
/*
* Copyright (C) 2016 Square, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
import java.math.BigInteger
interface Fibonacci {
fun fib(n: Int): Int
}
object LawfulGood : Fibonacci {
override fun fib(n: Int): Int {
check(n >= 0) { "fib is undefined for negative values: $n" }
return when (n) {
@swankjesse
swankjesse / SuspendReturnTest.kt
Created November 3, 2025 22:22
Demonstrates a bug in the Kotlin 2.2.21 compiler
import assertk.assertThat
import assertk.assertions.isEqualTo
import kotlin.test.Test
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
class SuspendReturnTest {
@Test
@swankjesse
swankjesse / RuntimePropertiesDecoder.kt
Created September 17, 2025 14:18
Attach bonus properties to a protobuf message
package com.squareup.wire.samples
import com.squareup.wire.Message
import com.squareup.wire.ProtoAdapter
import com.squareup.wire.ProtoReader32
import com.squareup.wire.ProtoWriter
import com.squareup.wire.forEachTag
import okio.Buffer
/**
/*
* Copyright (C) 2013 Square, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
import java.awt.Rectangle
import java.io.Closeable
import java.io.IOException
import java.util.zip.CRC32
import okio.Buffer
import okio.BufferedSink
import okio.BufferedSource
import okio.ByteString
import okio.ByteString.Companion.encodeUtf8
import okio.ByteString.Companion.toByteString
@swankjesse
swankjesse / Main.java
Created February 4, 2025 23:56
ClassLoader close bug
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.jar.JarOutputStream;
import java.util.zip.ZipEntry;
import static java.nio.charset.StandardCharsets.UTF_8;