Skip to content

Instantly share code, notes, and snippets.

View scottyab's full-sized avatar

Scott Alexander-Bown scottyab

View GitHub Profile
@scottyab
scottyab / GetUserProfile.kt
Last active October 24, 2024 11:24
Simple way of determining is the app is running in the context of main user, managed profile, other (i.e private space) or unknown. Potentially useful for alerting users if your app should not be used in PrivateSpace.
import android.content.Context
import android.os.Build
import android.os.UserManager
// Enum to represent the user profile types
enum class UserProfile {
MAIN_USER,
MANAGED_PROFILE,
OTHER_PROFILE,
UNKNOWN
@scottyab
scottyab / meetup-graphql-query-variables.txt
Last active August 21, 2024 18:03
Query all the past events a meetup.com group has hosted. Meetup doesn’t great way of surfacing a meetup groups past events (paging through the calendar is PITA). This GraphQL query can be run from the MeetupAPI GraphQL playground https://www.meetup.com/api/playground/#graphQl-playground
{ "urlname": "YOUR URL PATH here, for https://www.meetup.com/swmobile the urlname is swmobile" }
@scottyab
scottyab / AssertExtensions.kt
Created March 20, 2023 10:31
Assert `isInstanceOf` extensions to improve readablity of JUnit test assertions. I've found this most useful when asserting sealed class result objects as you can asset it's the correct type and then via smart casting continue to assert any specifics of the result, in the sample below I assert the type and then taskId.
import org.assertj.core.api.AbstractObjectAssert
@Suppress("UNCHECKED_CAST")
inline fun <reified R> AbstractObjectAssert<*, *>.isNotInstanceOf(): AbstractObjectAssert<*, *>? =
isNotInstanceOf(R::class.java)
@Suppress("UNCHECKED_CAST")
inline fun <reified R> AbstractObjectAssert<*, *>.isInstanceOf(): AbstractObjectAssert<*, *>? =
isInstanceOf(R::class.java)
@scottyab
scottyab / KoltinUnitTestTemplate.kt
Created February 9, 2023 11:46
Jetbrains IDE code template for JUnit tests written in Kotlin.
package ${PACKAGE_NAME}
import com.nhaarman.mockitokotlin2.verify
import com.nhaarman.mockitokotlin2.whenever
import org.assertj.core.api.Assertions.assertThat
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mock
import org.mockito.junit.MockitoJUnitRunner
@scottyab
scottyab / firebase-hosting-deploy.yml
Last active January 4, 2023 09:51
Github action used on Scottyab.com to Build Jekyll and Deploy to Firebase Hosting when commits pushed to main. `GITHUB_TOKEN`, `FIREBASE_PROJECT_ID`, `FIREBASE_SERVICE_ACCOUNT` will vary for your setup and need to be configured via Githuib repo settings..
name: Build and Deploy to Firebase
'on':
push:
branches:
- main
jobs:
build_and_deploy:
name: Build and deploy Jekyll site
runs-on: ubuntu-latest
@scottyab
scottyab / MyAppFirebaseMessagingService.kt
Last active August 17, 2020 13:32
Sample of how an app "MyApp" would intergrate and enable Beacon SDK push notifications
class MyAppFirebaseMessagingService : FirebaseMessagingService() {
override fun onMessageReceived(remoteMessage: RemoteMessage) {
if(remoteMessage.data.isNotEmpty()) {
processNewMessage(remoteMessage.data)
}
}
private fun processNewMessage(remoteMessageData: Map<String, String>) {
if (BeaconPushNotificationsProcessor.isBeaconNotification(remoteMessageData)) {
@scottyab
scottyab / SampleEncPrefs.kt
Created July 24, 2019 20:12
Simple example of using EncrypredSharedPreferences
package com.scottyab.whatsnewplayground.data
import android.content.Context
import android.content.SharedPreferences
import androidx.security.crypto.EncryptedSharedPreferences
import androidx.security.crypto.MasterKeys
import com.scottyab.whatsnewplayground.BuildConfig
internal class SampleEncPrefs(context: Context) {
@scottyab
scottyab / Coloring.java
Created October 29, 2018 15:22 — forked from milosmns/Coloring.java
Android: Coloring (Helper Class)
package me.angrybyte.coloringdemo;
import static android.graphics.PorterDuff.Mode.SRC_ATOP;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Bitmap;
#!/usr/bin/env bash
# exit if fails
set -o errexit
set -o pipefail
# reads the first arg as the file - expected list of file names without extension
filename="${1:-}"
# loops through each line
while read -r line
@scottyab
scottyab / add-copyright.py
Last active May 24, 2018 09:17 — forked from rodrigosetti/add-copyright.py
Adds Copyright Notice to a bunch of Java and Kotlin files