Skip to content

Instantly share code, notes, and snippets.

View khahani's full-sized avatar
💻
Happy coding...

Mohammadreza Khahani khahani

💻
Happy coding...
View GitHub Profile
@khahani
khahani / Creating a thread with the Thread class.cs
Last active February 8, 2017 13:42
ایجاد یک thread با استفاده از کلاس Thread
using System;
using System.Threading;
namespace Chapter1
{
public static class Program
{
public static void ThreadMethod()
{
for (int i = 0; i < 10; i++)
@khahani
khahani / leafletjs-example.html
Last active February 21, 2017 06:39
مثالی ساده از استفاده leaflet در وب
<!DOCTYPE html>
<html>
<meta charset="utf-8"/>
<head>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.0.3/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet@1.0.3/dist/leaflet.js"></script>
<style type="text/css">
#mapid { height: 400px; }
</style>
</head>
@khahani
khahani / leafletjs-example using openstreet.html
Last active February 4, 2018 15:41
استفاده از leaflet با openstreet
<!DOCTYPE html>
<html>
<meta charset="utf-8"/>
<head>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.0.3/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet@1.0.3/dist/leaflet.js"></script>
<style type="text/css">
#mapid { height: 400px; }
</style>
</head>
@khahani
khahani / CheckSignature.java
Created December 24, 2020 10:25
How to check Android app signature at runtime
public class foo {
private boolean isOldSignature() {
Context context = this;
final String SIGNATURE = "Put your app signature after retrive in log";
final boolean VALID = true;
final boolean INVALID = false;
try {
PackageInfo packageInfo = context.getPackageManager()
.getPackageInfo(context.getPackageName(),
@khahani
khahani / Sumup.kt
Created August 4, 2023 09:06
Lambda and method reference
class Button(
private val onClick: () -> Unit
) {
fun performClick() {
onClick()
}
}
class ButtonClickListener(
var name: String
@khahani
khahani / AppDispatcher.kt
Created September 17, 2023 16:05
AppDispatcher.kt
import javax.inject.Qualifier
@Qualifier
annotation class Dispatcher(val appDispatcher: AppDispatchers)
enum class AppDispatchers {
Default,
IO,
}
@khahani
khahani / DispatcherModules.kt
Last active September 17, 2023 16:13
DispatcherModules.kt
import [your_app_package].common.network.AppDispatchers.Default
import [your_app_package].common.network.AppDispatchers.IO
import [your_app_package].common.network.Dispatcher
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
@khahani
khahani / CoroutineScopesModule.kt
Created September 17, 2023 16:27
CoroutineScopesModule.kt
import [your_app_package].core.network.Dispatcher
import [your_app_package].core.network.AppDispatchers.Default
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.SupervisorJob
import javax.inject.Qualifier
@khahani
khahani / UpdateCoroutineScope.kt
Created September 17, 2023 16:36
UpdateCoroutineScope.kt
@Module
@InstallIn(SingletonComponent::class)
object CoroutineScopesModule {
@Provides
@Singleton
@ApplicationScope
fun providesApplicationScopeWithIODiapatcher(
@Dispatcher(IO) ioDispatcher: CoroutineDispatcher,
@ApplicationScope scope: CoroutineScope,
): CoroutineScope = CoroutineScope(scope.coroutineContext + ioDispatcher) // <- What I meant by updating dispatcher
@khahani
khahani / Result.kt
Created September 17, 2023 16:43
Result.kt
sealed interface Result<out T> {
data class Success<T>(val data: T) : Result<T>
data class Error(val exception: Throwable? = null) : Result<Nothing>
data object Loading : Result<Nothing>
}