Skip to content

Instantly share code, notes, and snippets.

View karim-eg's full-sized avatar
🇵🇸
Free Palestine

Karim Abdallah karim-eg

🇵🇸
Free Palestine
View GitHub Profile
@karim-eg
karim-eg / discord_bot.py
Created July 5, 2024 20:31
Discord Bot For Memes
"""
Made By Karim Abdallah, Android Engineer.
contact: karim@kotect.com
website: https://kotect.com
"""
import json
import discord
import requests
@karim-eg
karim-eg / rock_paper_scissors.py
Created July 5, 2024 20:10
Rock Paper Scissors
"""
Made By Karim Abdallah, Android Engineer.
contact: karim@kotect.com
website: https://kotect.com
"""
import time
import random
CHOICES = {
@karim-eg
karim-eg / main.kt
Last active September 7, 2023 21:00
Full Activity Code For Using DataStore
import android.annotation.SuppressLint
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.datastore.preferences.core.edit
import co.encept.datastore.databinding.ActivityMainBinding
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
class MainActivity : AppCompatActivity() {
@karim-eg
karim-eg / main.kt
Created September 7, 2023 20:54
Delete Saved Data In DataStore
private suspend fun deleteUserData() {
user.edit { usrData ->
usrData.clear()
}
}
@karim-eg
karim-eg / main.kt
Created September 7, 2023 20:41
Get Saved Data Using DataStore
private suspend fun getUserData() {
user.data.collect { usrData ->
val name = usrData[DataStoreKeys.USER_NAME] ?: "none"
val email = usrData[DataStoreKeys.EMAIL] ?: "none"
}
}
@karim-eg
karim-eg / main.kt
Created September 7, 2023 20:17
Save User Data Using DataStore
private suspend fun saveUserData(name: String, email: String) {
user.edit { usrData ->
usrData[DataStoreKeys.USER_NAME] = name
usrData[DataStoreKeys.EMAIL] = email
}
}
@karim-eg
karim-eg / DataStoreKeys.kt
Created September 7, 2023 17:37
DataStore Keys
object DataStoreKeys {
val USER_NAME = stringPreferencesKey("user_name")
val EMAIL = stringPreferencesKey("email")
}
@karim-eg
karim-eg / dataStoreInit.kt
Last active September 7, 2023 16:55
Data Store Init
val Context.user: DataStore<Preferences> by preferencesDataStore(name = "userInfo")
@karim-eg
karim-eg / build.gradle
Last active September 7, 2023 17:32
DataStore Implementation
dependencies {
// DataStore
implementation "androidx.datastore:datastore-preferences:1.0.0"
implementation "androidx.datastore:datastore-preferences-core:1.0.0"
}