Skip to content

Instantly share code, notes, and snippets.

View joshafeinberg's full-sized avatar

Josh Feinberg joshafeinberg

View GitHub Profile
@joshafeinberg
joshafeinberg / dependency-analysis-config.gradle
Last active July 27, 2022 04:20
Using Version Catalogs with Dependency Analysis Plugin
ext.reversedMap = [:] as Map<String, String>
void buildReversedMap(String versionCatalogName) {
def versionCatalog = rootProject.extensions
.getByType(VersionCatalogsExtension).named(versionCatalogName)
reversedMap = versionCatalog.getDependencyAliases()
.collectEntries { alias ->
def versionCatalogAlias = "${versionCatalogName}.${alias}"
def module = versionCatalog.findDependency(alias).get().get()
def fullModuleName = "${module.getModule()}:${module.getVersionConstraint()}"
fun Application.kodeinApplication(
kodeinMapper: Kodein.MainBuilder.(Application) -> Unit = {}
) {
val application = this
val kodein = Kodein {
bind<Application>() with instance(application)
kodeinMapper(this, application)
}
class Services(
sicknessService: SicknessService,
weightService: WeightService,
statsService: StatsService
) : OreoTrackerNetwork,
SicknessService by sicknessService,
WeightService by weightService,
StatsService by statsService
class WeightController(kodein: Kodein) : KodeinController(kodein), WeightService {
private val repository: WeightRepository by instance()
override suspend fun getWeights(): List<Weight> {
return repository.list()
}
override suspend fun postWeight(body: Weight) {
repository.addWeight(body)
interface OreoTrackerNetwork : SicknessService, WeightService, StatsService
interface SicknessService {
@GET("throwup")
suspend fun getThrowUps(): List<ThrowUp>
@POST("throwup")
suspend fun postThrowUp(@Body body: ThrowUp)
}
@joshafeinberg
joshafeinberg / index.js
Created April 30, 2017 04:47
CTA Bus Lookup With Permissions
/*
* Copyright (C) 2017 Josh Feinberg
*
* 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
@joshafeinberg
joshafeinberg / index.js
Created April 29, 2017 18:28
CTA Bus Lookup for API.AI
/*
* Copyright (C) 2017 Josh Feinberg
*
* 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
class CrashTree extends Timber.Tree {
@Override
protected void log(int priority, String tag, String message, Throwable t) {
if (t != null && priority == Log.ERROR) {
throw new RuntimeException(t);
}
}
}
@joshafeinberg
joshafeinberg / HostSelectionInterceptor.java
Last active September 26, 2016 16:30 — forked from swankjesse/HostSelectionInterceptor.java
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;