Skip to content

Instantly share code, notes, and snippets.

View cutiko's full-sized avatar

Erick Navarro cutiko

View GitHub Profile
@cutiko
cutiko / SimplestPlaceholderFragment.kt
Last active October 1, 2021 18:58
Simplest Placeholder Fragment for testing navigation
View SimplestPlaceholderFragment.kt
class SimplestPlaceholderFragment : Fragment() {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return TextView(requireContext()).apply {
text = "PLACE HOLDER FRAGMENT"
gravity = Gravity.CENTER
@cutiko
cutiko / AppSignatureHelper.java
Last active September 14, 2021 18:44
Sms login
View AppSignatureHelper.java
import android.content.Context;
import android.content.ContextWrapper;
import android.content.pm.PackageManager;
import android.content.pm.Signature;
import android.util.Base64;
import android.util.Log;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
@cutiko
cutiko / FunctionDefaultValue.kt
Created June 25, 2020 18:29
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 21:12
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 November 22, 2019 18:24
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 October 28, 2019 13:18
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 September 10, 2019 21:20
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 July 20, 2019 02:37
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 July 3, 2019 17:23
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 June 6, 2019 15:02
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}")