Skip to content

Instantly share code, notes, and snippets.

@ZacSweers
ZacSweers / OkioAtomicFile.kt
Created September 16, 2018 06:02
Okio/AtomicFile interop kotlin extensions
import android.util.AtomicFile
import okio.Buffer
import okio.Sink
import okio.sink
import okio.source
import java.io.FileOutputStream
import java.io.IOException
fun AtomicFile.source() = openRead().source()
package com.squareup.refmt
import okio.Okio
import java.io.File
fun main(args: Array<String>) {
val directory = File(args[0])
Reformatter().reformatDirectory(directory)
}
@cbeyls
cbeyls / KotlinFunctions.md
Last active June 20, 2022 14:59
Comparison of Kotlin functions: also, apply, let, run, with
Function Function type Target passed as Returns
also Extension it Target
apply Extension this Target
let Extension it Block return value
run Extension this Block return value
with Regular this Block return value
@autovalue
autovalue / ConverterCallAdapterFactory.java
Created April 5, 2017 21:31
Retrofit ConverterCallAdapterFactory implementation. A way to use the current request to convert the ResponseBody to a different class type.
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import okhttp3.Request;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.CallAdapter;
@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
/*
* 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
@lisawray
lisawray / ColumnItemDecoration.java
Last active May 29, 2023 21:11
Equal column spacing in a RecyclerView with GridLayoutManager
package com.example.columnspacing
import android.graphics.Paint;
import android.graphics.Rect;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
/*
* Copyright (C) 2016 Jesse Wilson
*
* 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
@JakeWharton
JakeWharton / Java6.java
Last active May 28, 2022 16:14
A comparison between non-capturing and capturing expressions across Java 6, Java 8, Java 8 with Retrolambda, Kotlin with native function expressions, and Kotlin with Java SAM expression.
import java.util.Arrays;
class NonCapturing {
public static void main(String... args) {
run(new Runnable() {
@Override public void run() {
System.out.println("Hey!");
}
});
}
@stephenlb
stephenlb / animated-gif.md
Last active October 31, 2020 22:57
DIY How to make your own HD Animated GIF Generator

HD Animated GIF Generator

You can make your own HD animated GIF generator.
Follow along with these commands to get started.

HD Animated GIF Generator

git clone git://source.ffmpeg.org/ffmpeg.git
cd ffmpeg