Skip to content

Instantly share code, notes, and snippets.

Avatar
💅
coding makes my nails polish peel

Amir A pantos27

💅
coding makes my nails polish peel
View GitHub Profile
View SomeViewModel.kt
viewModel.viewState.observe(viewLifecycleOwner) { state ->
state takeIfSuccess {
// Here's the success state
} takeIfError {
// Here's the error state
}
}
@pantos27
pantos27 / ConstraintLayoutWithDisableSupport.kt
Created Nov 17, 2020
ConstraintLayout with an option to grey out the entire content (disabled like)
View ConstraintLayoutWithDisableSupport.kt
package com.example.grayscaleexperiment
import android.content.Context
import android.graphics.Canvas
import android.graphics.ColorMatrix
import android.graphics.ColorMatrixColorFilter
import android.graphics.Paint
import android.util.AttributeSet
import androidx.constraintlayout.widget.ConstraintLayout
@pantos27
pantos27 / intercom.js
Created Sep 21, 2020
Helper methods to use Intercom in a type script project
View intercom.js
//https://www.intercom.com/help/en/articles/170-integrate-intercom-in-a-single-page-app
const Intercom = {
init: (appId) => {
console.log("Intercom", "init", appId);
const w = window;
const ic = w.Intercom;
w.intercomSettings = {
horizontal_padding: 24,
vertical_padding: 24,
View DialogBuilder.kt
package com.pantos27.gist
import android.os.Bundle
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.FragmentManager
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.Window
import android.widget.FrameLayout
@pantos27
pantos27 / KotlinView.kt
Created Jul 9, 2019
Android custom view in Kotlin with all the constructor overloads
View KotlinView.kt
package com.pantos27.gist
class KotlinView @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : View(context, attrs, defStyleAttr){
init{
//init stuff
}
}
@pantos27
pantos27 / ApplicationWatcher.kt
Last active Sep 25, 2020
A utility class to keep track if your app is in the foreground or background
View ApplicationWatcher.kt
package com.pantos27.hamburgersforbreakfast
import android.app.Activity
import android.os.Bundle
/**
* A utility class to keep track if your app is in the foreground or background
* without any special permission or API restrictions
* Note that if your app has any activities that run on a different
* process (through the process attribute in your manifest) this utility might not be persistent
*
@pantos27
pantos27 / DefaultViewHolder.kt
Created Dec 15, 2017
DefaultViewHolder for a recycler view that handles most use cases needed. Props to this tutorial https://www.raywenderlich.com/172711/intermediate-recyclerview
View DefaultViewHolder.kt
package com.pantos27.someproject.recycler
import android.support.annotation.IdRes
import android.support.v7.widget.RecyclerView
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import java.util.*
@pantos27
pantos27 / util.java
Created Oct 18, 2017
Android get resource uri
View util.java
private Uri getResourceUri(Resources resources, int resourceID) {
return Uri.parse("android.resource://"+resources.getResourcePackageName(resourceID)+"/"+
resources.getResourceTypeName(resourceID) + '/'
+ resources.getResourceEntryName(resourceID) );
}
@pantos27
pantos27 / md5.java
Created Jun 4, 2017
hash a string with MD5 in Java with MessageDigest
View md5.java
final MessageDigest md5 = MessageDigest.getInstance("MD5");
final byte[] digest = md5.digest(text.getBytes());
String hash = new String(digest);
@pantos27
pantos27 / CMDProcessor.java
Last active May 17, 2017
SU and SH in Java/Android
View CMDProcessor.java
package com.com.com;
import android.util.Log;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.InputStream;
public class CMDProcessor {