Skip to content

Instantly share code, notes, and snippets.

Erick Navarro cutiko

View GitHub Profile
@cutiko
cutiko / FunctionDefaultValue.kt
Created Jun 25, 2020
A function as default value for argument in function, the default value function has also argument, wonders of Kotlin
View FunctionDefaultValue.kt
class FunctionDefaultValue {
companion object {
@JvmStatic
fun main(args: Array<String>) {
val result = foo(2)
println(result)
}
fun foo(int: Int, boolean: Boolean = bar(int)): String {
@cutiko
cutiko / FakeAdapter
Created May 7, 2020
Fake RecyclerView Adapter for testing purpose
View FakeAdapter
private class FakeAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = object :
RecyclerView.ViewHolder(TextView(parent.context)) {}
override fun getItemCount() = 100
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
(holder.itemView as? TextView)?.text = position.toString()
}
@cutiko
cutiko / Readme.md
Created Nov 22, 2019
Git delete last commit
View Readme.md

Removing the last commit

To remove the last commit from git, you can simply run git reset --hard HEAD^ If you are removing multiple commits from the top, you can run git reset --hard HEAD~2 to remove the last two commits. You can increase the number to remove even more commits.

If you want to "uncommit" the commits, but keep the changes around for reworking, remove the "--hard": git reset HEAD^ which will evict the commits from the branch and from the index, but leave the working tree around.

If you want to save the commits on a new branch name, then run git branch newbranchname before doing the git reset.

ORIGINAL did fork but search didn't helped me

@cutiko
cutiko / CheckInternet.kt
Created Oct 28, 2019
Check if there is internet available
View CheckInternet.kt
private fun isNoInternet(context: Context): Boolean {
val connectionManager =
context.getSystemService(Context.CONNECTIVITY_SERVICE) as? ConnectivityManager
@Suppress("DEPRECATION")
return connectionManager?.let {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
it.getNetworkCapabilities(it.activeNetwork)?.run {
when {
hasTransport(NetworkCapabilities.TRANSPORT_WIFI) -> false
hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR) -> false
@cutiko
cutiko / Copier.kt
Last active Sep 10, 2019
How does copy works on Kotlin
View Copier.kt
package copier
import java.util.*
class Copier {
companion object {
@JvmStatic
fun main(args: Array<String>) {
println("lets see default behaviour")
@cutiko
cutiko / JavaAdapter.java
Created Jul 20, 2019
Adapter template for Android Studio
View JavaAdapter.java
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.recyclerview.widget.RecyclerView;
#set($model = $NAME.replace('sAdapter', ''))
#set($holder = $model+'Holder')
#set($item = $model.toLowerCase())
@cutiko
cutiko / RestartAppAdb.md
Created Jul 3, 2019
Restart Android App using ADB
View RestartAppAdb.md

Remember to replace com.domain.appname with your actual app package name

adb shell am force-stop com.domain.appname
adb shell am start -n com.domain.appname/com.domain.appname.MainActivity
@cutiko
cutiko / infinity.kt
Created Jun 6, 2019
Inifinity is a double
View infinity.kt
fun main(args: Array<String>) {
System.out.println("Lets buy beer")
buyBeer(1.0)
buyBeer(2.0)
buyBeer("Infinity".toDouble())
}
fun buyBeer(beer : Double) = System.out.println("You are buying $beer beers and is more than one beer ${beer > 1}")
@cutiko
cutiko / index.js
Created May 2, 2019
Functions custom claims example
View index.js
exports.userCreationListener = functions.auth.user().onCreate(user => {
const admins = {
"first@admin.com": true
};
const email = user.email;
if (!admins[email]) {
return false;
}
const uid = user.uid;
return admin.auth().setCustomUserClaims(uid, {superAdmin: true}).then(
@cutiko
cutiko / Timezones.md
Last active Mar 15, 2019
All the TimeZone IDS
View Timezones.md
You can’t perform that action at this time.