Skip to content

Instantly share code, notes, and snippets.

View k0shk0sh's full-sized avatar

Kosh Sergani k0shk0sh

View GitHub Profile
@k0shk0sh
k0shk0sh / keybase.md
Last active April 4, 2017 13:37
keybase.md

Keybase proof

I hereby claim:

  • I am k0shk0sh on github.
  • I am imkosh (https://keybase.io/imkosh) on keybase.
  • I have a public key whose fingerprint is B21B 490E C3C3 1E29 FC36 A7D8 2950 DD2D A315 EE38

To claim this, I am signing this object:

/*
* Copyright 2016 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@k0shk0sh
k0shk0sh / code.kt
Created March 4, 2018 10:41 — forked from chrisbanes/code.kt
Night Mode inflater
/*
* Copyright 2017 Google, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@k0shk0sh
k0shk0sh / file.kt
Created October 13, 2018 16:31
Nested Fragments talking to their parent fragment via scoped Activity ViewModel
class ProfileActivityViewModel : ViewModel() {
val tabCounterLiveData = MutableLiveData<Pair<String, Long>>()
}
class ProfileActivity : AppCompatActivity() {
@Inject lateinit var viewModelFactory: ViewModelProvider.Factory
private val viewModel by lazy { ViewModelProviders.of(this, viewModelFactory).get(ProfileActivityViewModel::class.java) }
}
class ParentFragment : Fragment() {
@k0shk0sh
k0shk0sh / AESEncryptDecrypt.kt
Created December 15, 2020 03:11 — forked from reuniware/AESEncryptDecrypt.kt
(Android/Kotlin) Encrypt and Decrypt with AES algorithm, and save/restore Secret Key and Inizialization Vector in SharedPreferences
fun encrypt(context:Context, strToEncrypt: String): ByteArray {
val plainText = strToEncrypt.toByteArray(Charsets.UTF_8)
val keygen = KeyGenerator.getInstance("AES")
keygen.init(256)
val key = keygen.generateKey()
saveSecretKey(context, key)
val cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING")
cipher.init(Cipher.ENCRYPT_MODE, key)
val cipherText = cipher.doFinal(plainText)
@k0shk0sh
k0shk0sh / AESEncryptDecrypt.kt
Created December 15, 2020 03:11 — forked from reuniware/AESEncryptDecrypt.kt
(Android/Kotlin) Encrypt and Decrypt with AES algorithm, and save/restore Secret Key and Inizialization Vector in SharedPreferences
fun encrypt(context:Context, strToEncrypt: String): ByteArray {
val plainText = strToEncrypt.toByteArray(Charsets.UTF_8)
val keygen = KeyGenerator.getInstance("AES")
keygen.init(256)
val key = keygen.generateKey()
saveSecretKey(context, key)
val cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING")
cipher.init(Cipher.ENCRYPT_MODE, key)
val cipherText = cipher.doFinal(plainText)