Skip to content

Instantly share code, notes, and snippets.

View Pavneet-Sing's full-sized avatar
🎯
Focusing | Open to remote work

Pavneet Singh Pavneet-Sing

🎯
Focusing | Open to remote work
View GitHub Profile
@antonyharfield
antonyharfield / RailwayOP-CompleteExample.kt
Created April 29, 2019 17:51
Railway Oriented Programming in Kotlin (as described here)
// Result is a superpowered enum that can be Success or Failure
// and the basis for a railway junction
sealed class Result<T>
data class Success<T>(val value: T): Result<T>()
data class Failure<T>(val errorMessage: String): Result<T>()
// Composition: apply a function f to Success results
infix fun <T,U> Result<T>.then(f: (T) -> Result<U>) =
when (this) {
is Success -> f(this.value)
@dlew
dlew / script.sh
Created November 9, 2018 16:36
Simple AndroidX Migration Script
#!/usr/bin/env bash
# I've found that the "Migrate to AndroidX" converter in Android Studio doesn't work very
# well, so I wrote my own script to do the simple job of converting package names.
#
# You can download a CSV of package names here: https://developer.android.com/topic/libraries/support-library/downloads/androidx-class-mapping.csv
#
# It'll run faster on a clean build because then there are fewer files to scan over.
#
# Uses `gsed` because I'm on a Mac. Can easily replace with `sed` if you don't have `gsed`.
@JoseAlcerreca
JoseAlcerreca / EventObserver.kt
Created April 26, 2018 12:14
An Observer for Events, simplifying the pattern of checking if the Event's content has already been handled.
/**
* An [Observer] for [Event]s, simplifying the pattern of checking if the [Event]'s content has
* already been handled.
*
* [onEventUnhandledContent] is *only* called if the [Event]'s contents has not been handled.
*/
class EventObserver<T>(private val onEventUnhandledContent: (T) -> Unit) : Observer<Event<T>> {
override fun onChanged(event: Event<T>?) {
event?.getContentIfNotHandled()?.let { value ->
onEventUnhandledContent(value)
@Ashton-W
Ashton-W / Issue.md
Last active April 23, 2024 17:19
GitHub Markdown toggle code block
Click to toggle contents of `code`
CODE!
@vaughandroid
vaughandroid / ViewVisibilityIdlingResource.java
Created August 21, 2015 07:58
An IdlingResource for Espresso which blocks until a View has a particular visibility state.
package com.vaughandroid.test.espresso.idlingresources;
import android.app.Activity;
import android.os.Handler;
import android.support.annotation.IdRes;
import android.support.annotation.NonNull;
import android.support.test.espresso.*;
import android.view.View;
import java.lang.ref.WeakReference;
@stkent
stkent / android_studio_shortcuts.md
Last active November 1, 2023 11:58
Android Studio Shortcuts (Mac)

Android Studio Shortcuts (Mac)

Notes:

  • Two of the most useful shortcuts utilize the Fn (function) keys. It is therefore recommended that you enable the "Use all F1, F2, etc. keys as standard function keys" option [System Preferences > Keyboard].
  • Be sure to enable the Mac OS X 10.5+ keymap in Android Studio [Preferences > Keymap].
  • A fairly complete shortcut list can be found here.

Useful symbols: