Skip to content

Instantly share code, notes, and snippets.

View cutiko's full-sized avatar

Erick Navarro cutiko

View GitHub Profile
@cutiko
cutiko / ContentView.Swift
Created April 24, 2024 15:55
Swift UI Dynamic focus for forms
struct ContentView: View {
@FocusState private var focusedInput: Inputs?
@State private var firstInput = ""
@State private var secondInput = ""
var body: some View {
VStack {
TextField("FIRST", text: $firstInput)
.focused($focusedInput, equals: .firstInput)
@cutiko
cutiko / ContentView.Swift
Created April 18, 2024 16:00
Hoisted state for forms in iOS (with UI Model)
import SwiftUI
struct ContentView: View {
@ObservedObject var viewModel = FormViewModel()
var body: some View {
VStack {
SimpleInput($viewModel.screenState.firstInput) {
print("CUTIKO_TAG FIRST focus lost")
@cutiko
cutiko / Android.kt
Last active April 17, 2024 20:12
On Focus Lost iOS and Android
@OptIn(ExperimentalMaterial3Api::class)
@Composable
private fun SimpleInput(onFocusLost: ()-> Unit) {
var textValue by remember { mutableStateOf("") }
var previousFocus by remember { mutableStateOf(false) }
TextField(
value = textValue,
onValueChange = { textValue = it },
modifier = Modifier.onFocusChanged { it: FocusState ->
@cutiko
cutiko / SimplestPlaceholderFragment.kt
Last active October 1, 2021 18:58
Simplest Placeholder Fragment for testing navigation
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
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
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
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

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
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
package copier
import java.util.*
class Copier {
companion object {
@JvmStatic
fun main(args: Array<String>) {
println("lets see default behaviour")