Skip to content

Instantly share code, notes, and snippets.

View alifhasnain's full-sized avatar
🪲
debugging

Alif Hasnain alifhasnain

🪲
debugging
  • IOTA Infotech Limited
  • Dhaka,Bangladesh
View GitHub Profile
import java.util.Scanner;
/**
*
* @author Niloy
*/
public class Main {
public static void main(String[] args) {

Shortcuts

Open file in porject window: Alt+F1

Open project navigator Alt + 1

Move focus to editor Esc

Move Caret to Matching Brace Ctrl+Shift+M

import java.util.concurrent.LinkedBlockingQueue
import java.util.concurrent.ThreadPoolExecutor
import java.util.concurrent.TimeUnit
import kotlin.random.Random.Default.nextInt
/*
* Here queue size is defined 3
* so that means if the tasks in the queue exceeds 3 then the pool will create
@alifhasnain
alifhasnain / Quadruple.kt
Created September 17, 2020 14:54
Quadruple class for Kotlin
import java.io.Serializable
data class Quadruple<A,B,C,D>(var first: A, var second: B, var third: C, var fourth: D): Serializable {
override fun toString(): String = "($first, $second, $third, $fourth)"
}
@alifhasnain
alifhasnain / Event.kt
Created September 29, 2020 21:02
A Kotlin class which can help as being a wrapper around any other class to trigger the LiveData once.
class Event<out R>(private val data: R) {
var hasEventBeenHandled = false
private set
val content: R?
get() = if (!hasEventBeenHandled) {
hasEventBeenHandled = true
data
} else {
@alifhasnain
alifhasnain / UnitTestingNotes.md
Last active November 17, 2020 21:24
Unit Testing Notes

Instantiate a mock object (Without Annotation)

Mockito.mock(ClassName.class);

Instantiate a mock object (With Annotation)

@RunWith(MockitoJUnitRunner.class)
public class MyTestClassTest {
@alifhasnain
alifhasnain / GitNotes.md
Last active March 21, 2023 17:07
Git Notes

Add new remote

git remote add <origin_name> <url_of_the_remote_repo>

Update existing remote

git remote set-url <origin> <url_of_the_remote_repo>

To see remotes names

git remote

@alifhasnain
alifhasnain / NetworkUtils.kt
Created November 21, 2020 20:03
This is a class for observing network state. It was taken Foodium App.
import android.content.Context
import android.net.ConnectivityManager
import android.net.Network
import android.net.NetworkCapabilities
import android.net.NetworkRequest
import android.os.Build
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
/**
@alifhasnain
alifhasnain / RxJava Notes.md
Last active June 21, 2021 06:56
RxJava important notes.
@alifhasnain
alifhasnain / LocationObserver.java
Created February 8, 2021 20:18
Lifecycle aware location observer.
import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.IntentSender;
import android.content.pm.PackageManager;
import android.os.Looper;
import androidx.core.app.ActivityCompat;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver;