Skip to content

Instantly share code, notes, and snippets.

View sajjadjaved01's full-sized avatar
🏠
Working from home

Sajjad Javed sajjadjaved01

🏠
Working from home
View GitHub Profile
@sajjadjaved01
sajjadjaved01 / add_lang.dart
Last active November 3, 2023 10:37
Extract Strings from Flutter / Dart Project. Also if you are using Easy Localization, you can add one translation at a time to all json files.
import 'dart:io';
import 'dart:convert';
void updateLocalizationKeyInLanguages(
List<String> filePaths, String key, Map<String, String> translations) {
try {
for (String filePath in filePaths) {
File file = File(filePath);
if (file.existsSync()) {
@sajjadjaved01
sajjadjaved01 / main.tsx
Last active July 21, 2023 11:57
A React Native component that renders a set of animated reactions for a chat message. The component uses the Animated API to fade in/out the reactions, and allows the user to select a reaction by tapping on it. The selected reaction is then sent to the server to update the message's reactions.
const Main = () => {
const cuteReactionsRefs = useRef<React.RefObject<CuteReactionsRef>[]>([]);
// for show using ref
cuteReactionsRefs.current[message._id]?.current?.showReactions();
const check = () => {
if (!cuteReactionsRefs.current[props.currentMessage?._id]) {
cuteReactionsRefs.current[props.currentMessage?._id] =
@sajjadjaved01
sajjadjaved01 / click.scpt
Created May 26, 2022 04:14
apple script to click repeatedly.
activate application "Finder"
tell application "System Events"
tell process "Finder"
set endTime to 5
repeat while 8 is greater than endTime
click at {200 + endTime * 2, 5}
endTime - 1
delay 10
end repeat
end tell
@sajjadjaved01
sajjadjaved01 / Dropdown.tsx
Last active November 14, 2024 07:17
Multiselect / Single-Select dropdown.
import { MaterialIcons } from "@expo/vector-icons";
import React, { useCallback, useEffect, useMemo, useState } from "react";
import {
FlatList,
Image,
Pressable,
StyleSheet,
Text,
TouchableOpacity,
View,
@sajjadjaved01
sajjadjaved01 / State.kt
Last active March 31, 2021 12:01
Handle API States
sealed class State<T> {
class Loading<T> : State<T>()
data class Success<T>(val data: T) : State<T>()
data class Error<T>(val message: String) : State<T>()
companion object {
/**
@sajjadjaved01
sajjadjaved01 / AndroidAnimation.kt
Created January 8, 2020 14:40
Android Animation using AndroidX Transition API.
/* usage fabMessages.toggle(Slide(Gravity.Bottom)) : Slide() & Fade() */
fun View.toggle(transition: Transition) {
transition.duration = 500
transition.addTarget(this)
TransitionManager.beginDelayedTransition(this.parent as ViewGroup, transition)
visibility = if (!isVisible) View.VISIBLE else View.GONE
}
// Usage extend any of your view with toggle, like (Button, FabButton, etc).
// use views Id.
@sajjadjaved01
sajjadjaved01 / ActivitiesLaunchingWay.kt
Created December 27, 2019 07:40 — forked from wajahatkarim3/ActivitiesLaunchingWay.kt
Kotlin Extensions for simpler, easier and funw way of launching of Activities
/**
* Kotlin Extensions for simpler, easier and funw way
* of launching of Activities
*/
inline fun <reified T : Any> Activity.launchActivity (
requestCode: Int = -1,
options: Bundle? = null,
noinline init: Intent.() -> Unit = {})
{
@sajjadjaved01
sajjadjaved01 / DemoData.kt
Last active February 25, 2021 09:43
Saving retrofit response Model to shared preferences. Using Generics
data class DemoData(
val email: String,
val name: String,
val username: String
)
// Usage For getting saved data.
var userData = getModelPref(getPreferences, localUserData, DemoData::class.java)
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME}#end
import androidx.recyclerview.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.AsyncListDiffer
import androidx.recyclerview.widget.DiffUtil
#parse("File Header.java")
@sajjadjaved01
sajjadjaved01 / DataBinding_with_ImageView.kt
Created August 28, 2019 14:24
DataBinding with ImageView & Glide
//Remember: The method needs to be public static and the first parameter will be the view. This is very important.
// this is for just for single loading.
companion object {
@JvmStatic
@BindingAdapter("profileImage")
fun loadImage(view: ImageView, profileImage: String) {
Glide.with(view.context)
.load(profileImage)
.into(view)