Skip to content

Instantly share code, notes, and snippets.

View BrantApps's full-sized avatar
🚀

David Branton BrantApps

🚀
View GitHub Profile
@BrantApps
BrantApps / resolve-flavored-assets-babel-plugin.js
Created May 4, 2023 08:45
Remove assets that aren't used a particular flavour of a react-native app
const GET_FLAVORED_ASSET_FUNCTION_NAME = "getFlavoredAsset"
module.exports = function ({types: t}) {
const isGetFlavoredAssetCall = (path) =>
t.isIdentifier(path.node.callee, {
name: GET_FLAVORED_ASSET_FUNCTION_NAME,
}) &&
((path.node.arguments.length === 1 &&
t.isObjectExpression(path.node.arguments[0])) ||
(path.node.arguments.length === 2 &&
@BrantApps
BrantApps / MapView.kt
Created November 19, 2019 02:16
Learning FP via arrow-kt. Could be right, could be wrong! 🤷
class MapView: Fragment(), MapReadyListener, LocationFoundListener {
@Inject lateinit var mappable: Mappable
@Inject lateinit var runtimePermissions: Set<String>
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
checkPermissions(requireActivity())
}
private fun checkPermissions(parentActivity: Activity) {
@BrantApps
BrantApps / fp-ts-get-db-ids-from-bulk-insert.ts
Last active November 19, 2019 02:17
Using fp-ts to iterate through a list of promises transforming them to a sequence then extracting the ids
import {pipe} from "fp-ts/lib/pipeable"
import * as A from "fp-ts/lib/Array"
import * as T from "fp-ts/lib/Task"
const ids = await pipe(
someListings,
A.map(listing => {
return () => persistence.createListing(listing)
}),
A.array.sequence(T.task),
@BrantApps
BrantApps / InMemoryDatabase.java
Created November 9, 2018 23:55
An older way of doing in-memory dbs on Android without Room.
package com.brantapps.oceanlife.domain.fixture;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import org.robolectric.RuntimeEnvironment;
/**
* In memory database for testing purposes.
*
@BrantApps
BrantApps / oceanlife-activity-fragment.graphml
Last active February 27, 2018 18:08
Degraph configuration file used within BrantApps/OceanLife to isolate and visualise package tangle. See http://blog.schauderhaft.de/degraph/ & https://github.com/schauder/degraph
output = oceanlife-activity-fragment.graphml
classpath = ../../../OceanLife/app/build/intermediates/classes/withAmazon/debug/com/brantapps/oceanlife/
# Don’t model dependencies
exclude = java*.**
exclude = android*.**
exclude = dagger*.**
exclude = rx*.**
exclude = okhttp*.**
exclude = org*.**
@BrantApps
BrantApps / TestActivityAnalytics.java
Last active July 18, 2017 16:51
A test that finds all of my app's Activitys and then ensures the tracking annotation @ScreenView exists. Friendly error message when you miss one.
package com.brantapps.oceanlife.activity;
import android.app.Activity;
import com.brantapps.oceanlife.analytics.aop.ScreenView;
import com.brantapps.oceanlife.analytics.event.Tags;
import com.brantapps.oceanlife.domain.activity.SplashActivity;
import com.brantapps.oceanlife.preference.activity.AboutActivity;
import com.brantapps.oceanlife.preference.activity.ApplicationPreferencesActivity;
import com.brantapps.oceanlife.preference.activity.DisclaimerActivity;
Observable.zip(
Observable.from(spots),
Observable.interval(SYNC_TICK, TimeUnit.MILLISECONDS),
(obs, timer) -> obs)
.subscribeOn(scheduler)
.observeOn(scheduler)
.unsubscribeOn(scheduler)
.flatMap(spot -> syncTidePosition.get().buildObservable(spot))
.subscribe(spotAndTideEvent -> new TideEventSubscriber(
lunaEventService,