Skip to content

Instantly share code, notes, and snippets.

View reline's full-sized avatar
🌈

Nathan Reline reline

🌈
View GitHub Profile
@reline
reline / JishoCompose.kt
Last active November 11, 2020 22:52
Sample for rendering a list of dictionary entries using Jetpack Compose
@Composable
fun DictionaryEntries(words: List<Word>) {
Column(modifier = Modifier.padding(all = 16.dp), verticalArrangement = Arrangement.spacedBy(32.dp)) {
for (word in words) {
Card(elevation = 2.dp, modifier = Modifier.fillMaxWidth(), shape = RoundedCornerShape(2.dp)) {
DictionaryEntry(word.rubies)
}
}
}
}
@reline
reline / build.gradle
Last active August 5, 2020 04:14
Kotlin Multiplatform JVM workaround
// java.lang.ClassNotFoundException
// java.lang.NoClassDefFoundError
// Could not find or load main class
// https://youtrack.jetbrains.com/issue/KT-29082
task execute(type: JavaExec) {
main = "com.github.MainKt"
classpath = objects.fileCollection().from(
tasks.named("compileKotlin"),
tasks.named("compileJava"), // if you have java sources or generated java sources
configurations.named("runtimeClasspath")
@reline
reline / SafeIntent.kt
Created October 11, 2019 20:08
Android type safe intents
private const val SHOW_GREETING_TOAST = "SHOW_GREETING_TOAST"
// alternatively, make this public for other activities to use
private var Intent.showGreetingToast: Boolean
set(value) { putExtra(SHOW_GREETING_TOAST, value) }
get() = getBooleanExtra(SHOW_GREETING_TOAST, false)
class MyActivity : Activity() {
companion object {
fun newIntent(context: Context, showGreetingToast: Boolean): Intent {
val intent = Intent(context, MyActivity::class.java)
@reline
reline / ColdObservableSingleSubscriberProxy.kt
Created September 19, 2019 15:56
RxObservable that only emits to first subscriber
fun <T> Observable<T>.toColdSingleSubscribeable(): Observable<T> {
return ColdObservableSingleSubscriberProxy(this)
}
class ColdObservableSingleSubscriberProxy<T>(private val observable: Observable<T>) : Observable<T>() {
private val hasBeenSubscribed = AtomicBoolean(false)
override fun subscribeActual(observer: Observer<in T>) {
if (hasBeenSubscribed.compareAndSet(false, true)) {
@reline
reline / hidekeyboard.kt
Created October 20, 2018 06:24
Android - hide keyboard
fun hideKeyboard() {
currentFocus?.windowToken?.let {
val imm = applicationContext?.getSystemService(InputMethodManager::class)
imm?.hideSoftInputFromWindow(it, InputMethodManager.HIDE_NOT_ALWAYS)
}
}
@reline
reline / main.go
Created March 10, 2018 23:48
Go server
package main
import (
"fmt"
"log"
"math/rand"
"net/http"
"time"
)
@reline
reline / .vimrc
Last active December 9, 2019 17:54
Vim config
execute pathogen#infect()
syntax on
set expandtab
set number
set ruler
set tabstop=4
filetype plugin indent on
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
@reline
reline / install.sh
Last active January 14, 2020 21:19
Ultimate Android build system dependency script (Ubuntu 14.04)
apt-get update
apt-get install -y software-properties-common
echo debconf shared/accepted-oracle-license-v1-1 select true | debconf-set-selections
echo debconf shared/accepted-oracle-license-v1-1 seen true | debconf-set-selections
add-apt-repository -y ppa:webupd8team/java
dpkg --add-architecture i386
apt-get update
apt-get install -y --force-yes apt-utils build-essential git unzip oracle-java8-installer python libreadline-dev curl bzip2 libssl-dev zlib1g-dev libc6:i386 libncurses5:i386 libstdc++6:i386 lib32z1 libbz2-1.0:i386
apt-get -fy install
git clone https://github.com/rbenv/rbenv.git $HOME/.rbenv
@reline
reline / CustomTrust.java
Last active August 24, 2022 12:45
Trusting self-signed certificates in Android using OkHttp
import okhttp3.*;
import okio.Buffer;
import javax.net.ssl.*;
import java.io.IOException;
import java.io.InputStream;
import java.security.GeneralSecurityException;
import java.security.KeyStore;
import java.security.cert.Certificate;
import java.security.cert.CertificateFactory;
@reline
reline / AsyncGeocoder.java
Last active April 18, 2021 02:14
Async RxAndroid wrapper for Android's Geocoder
import android.content.Context;
import android.location.Address;
import android.location.Geocoder;
import java.io.IOException;
import rx.Observable;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;