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
/*
* Copyright (C) 2021 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 okio.buffer
import okio.source
/**
* Converts a Kotlin file with `backtick method names` to camelCaseMethodNames.
*/
fun main() {
val source = System.`in`.source().buffer()
while (true) {
val line = source.readUtf8Line() ?: break
public final long readVarint64() throws IOException {
if (this.state != 0 && this.state != 2) {
throw (Throwable)(new ProtocolException("Expected VARINT or LENGTH_DELIMITED but was " + this.state));
} else {
int shift = 0;
for(long result = 0L; shift < 64; shift += 7) {
this.source.require(1L);
int var10001 = this.pos++;
byte b = this.source.readByte();
@swankjesse
swankjesse / ConcurrencyBenchmark.kt
Created June 13, 2020 15:34
Compare concurrency of various SegmentPool strategies
package okio.samples
import okio.Buffer
import okio.BufferedSink
import okio.BufferedSource
import okio.buffer
import okio.source
import java.io.File
import java.util.concurrent.atomic.AtomicLong
/*
* Copyright (C) 2020 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

JUnit Test Sharding

This is a JUnit extension that shards the tests for parallel execution.

It selects tests by hashing the test class and method name.

Configuration

Tests are sharded if these environment variables are present:

import java.io.IOException;
import okhttp3.Interceptor;
import okhttp3.Response;
import static okhttp3.internal.http.StatusLine.HTTP_PERM_REDIRECT;
import static okhttp3.internal.http.StatusLine.HTTP_TEMP_REDIRECT;
/**
* In OkHttp 4.5 and earlier, HTTP 307 and 308 redirects were only honored if the request method
* was GET or HEAD.
/*
* Copyright (C) 2020 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) {
/*
* Copyright (C) 2009 The Guava Authors
*
* 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