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 / MoshiKotlinExample.kt
Created May 14, 2017 17:15
Demo how to use Moshi with Kotlin
import com.squareup.moshi.Json
import com.squareup.moshi.KotlinJsonAdapterFactory
import com.squareup.moshi.Moshi
import com.squareup.moshi.Rfc3339DateJsonAdapter
import java.util.Date
val json = """
{
"url": "https://api.github.com/repos/square/okio/issues/156",
"id": 91393390,
/*
* 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
@swankjesse
swankjesse / SslContextBuilder.java
Created June 8, 2014 23:30
Execute this java program to generate an SSL context that contains pinned certificates.
/*
* 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
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) {
\\ //
\\ .ooo. //
.@@@@@@@@@.
:@@@@@@@@@@@@@:
:@@. '@@@@@' .@@:
@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@
:@@ :@@@@@@@@@@@@@@@@@. @@:
/*
* 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 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.
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 / Rip.java
Created February 8, 2013 23:27
Stream editor for Java nerds. Use Java regular expressions to break up lines, and Java format strings to put them back together again.
/*bin/mkdir /tmp/rip 2> /dev/null
javac -d /tmp/rip $0
java -cp /tmp/rip Rip "$@"
exit
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.util.regex.Matcher;