Skip to content

Instantly share code, notes, and snippets.

View simplekjl's full-sized avatar
🎯
Focusing

Jose Luis Crisostomo simplekjl

🎯
Focusing
  • Berlin, Germany
View GitHub Profile
/**
* @return [LiveData] with value produced from combining [source1] and [source2] using [combiner]
*
* This function produces new value only if [source1] and [source2] values are not null
*/
fun <T1, T2, R> combineNonNull(
source1: LiveData<T1>,
source2: LiveData<T2>,
combiner: (T1, T2) -> R
@GabrielBrasileiro
GabrielBrasileiro / ComponentCallbacksExtensions.kt
Last active October 14, 2022 02:57
Koin extensions to solve type erasure of generic mappers
/**
* This will recover and inject your interface in your fragments or activities
*/
inline fun <reified I, reified O> ComponentCallbacks.injectMapper(): Lazy<Mapper<I, O>> {
return inject(named(identifier<I, O>()))
}
@titoaesj
titoaesj / .kt
Last active March 17, 2024 22:22
Android convert int to dp
OBS: O var_number_int é a varável que recebera o valor a ser convertido em DP
(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, var_number_int, getResources().getDisplayMetrics())
##KOTLIN
val Int.dp: Int
get() = (this * Resources.getSystem().displayMetrics.density + 0.5f).toInt()
val Float.dp: Int
@cretz
cretz / kotlin-annoyances.md
Last active November 12, 2019 22:54
Kotlin Annoyances

Kotlin Annoyances

These are things that I found annoying writing a complex library in Kotlin. While I am also a Scala developer, these should not necessarily be juxtaposed w/ Scala (even if I reference Scala) as some of my annoyances are with features that Scala doesn't even have. This is also not trying to be opinionated on whether Kotlin is good/bad (for the record, I think it's good). I have numbered them for easy reference. I can give examples for anything I am talking about below upon request. I'm sure there are good reasons for all of them.

  1. Arrays in data classes break equals/hashCode and ask you to overload it. If you are going to need to overload it and arrays have no overridability, why not make the least-often use case (the identity-comparison equals) the exception?
@starkej2
starkej2 / RxImmediateSchedulerRule.kt
Last active December 30, 2021 18:33
RxJava Immediate Scheduler Test Rule
/**
* Replaces the default RxJava schedulers with a synchronous one.
*/
class RxImmediateSchedulerRule : TestRule {
private val immediateScheduler = object : Scheduler() {
@NonNull
override fun scheduleDirect(run: Runnable, delay: Long, unit: TimeUnit): Disposable {
// Hack to prevent stack overflows in unit tests when scheduling with a delay;
return super.scheduleDirect(run, 0, unit)
}
@robertpainsi
robertpainsi / README.md
Last active March 21, 2024 10:45
How to reopen a pull-request after a force-push?

How to reopen a pull-request after a force-push?

Precodinitions

  • You need the rights to reopen pull requests on the repository.
  • The pull request hasn't been merged, just closed.

Instructions

  1. Write down the current commit hash of your PR-branch git log --oneline -1 <PR-BRANCH>
  2. Write down the latest commit hash on github before the PR has been closed.
  3. git push -f origin :
Unless specified otherwise, all of the below tinting applies to both Lollipop and pre-Lollipop using AppCompat v21.
To use the support version of these attributes, remove the android namespace.
For instance, "android:colorControlNormal" becomes "colorControlNormal".
These attributes will be propagated to their corresponding attributes within the android namespace
for devices running Lollipop. Any exceptions to this will be noted by including the "android:" prefix.
All Clickable Views:
-----------
@sheharyarn
sheharyarn / CardSwingAnimations.md
Last active March 16, 2021 08:04
Swing Animations for CardViews in Android

SwingUp Animations for Android

I use these snippets to implement Google Now Card appear-animations on Android. Add these two files to your res/anim/ folder and add a swing_anim_time integer to your values:

<!-- res/values/strings.xml -->
<integer name="swing_anim_time">750</integer>
@mombrea
mombrea / volley-POST-example.java
Last active May 24, 2023 10:58
Example of performing a POST request using Google Volley for Android
public static void postNewComment(Context context,final UserAccount userAccount,final String comment,final int blogId,final int postId){
mPostCommentResponse.requestStarted();
RequestQueue queue = Volley.newRequestQueue(context);
StringRequest sr = new StringRequest(Request.Method.POST,"http://api.someservice.com/post/comment", new Response.Listener<String>() {
@Override
public void onResponse(String response) {
mPostCommentResponse.requestCompleted();
}
}, new Response.ErrorListener() {
@Override
@scottyab
scottyab / SignatureCheck.java
Last active January 30, 2024 15:22
Simple Android signature check. Please note: This was created in 2013, not actively maintained and may not be compatible with the latest Android versions. It's not particularly difficult for an attacker to decompile an .apk, find this tamper check, replace the APP_SIGNATURE with theirs and rebuild (or use method hooking to return true from `vali…
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.Signature;
public class TamperCheck {
//we store the hash of the signture for a little more protection
private static final String APP_SIGNATURE = "1038C0E34658923C4192E61B16846";