Skip to content

Instantly share code, notes, and snippets.

View rafsanahmad's full-sized avatar
🎯
Focusing

Rafsan Ahmad rafsanahmad

🎯
Focusing
View GitHub Profile
@rafsanahmad
rafsanahmad / KotlinCollectionFunctions.kt
Last active January 17, 2022 18:21
A collection of examples for Kotlin Collection functions. There are total 29 examples available. The examples contain usage of distinct(), reduce(), all(), single(), chunked(), copyInto(), find(), zip(), filter(), union(), map(), intersection(), groupBy(), sort(), reverse(), remove(), retain(), flatmap(), sum(), max(), min(), etc
import kotlin.math.roundToInt
data class User(
val id: Int,
val name: String,
val webDev: Boolean = false,
val mobileDev: Boolean = false
)
data class Product(val name: String, val quantity: Int, val price: Double)
Below are the Big O performance of common functions of different Java Collections.
List | Add | Remove | Get | Contains | Next | Data Structure
---------------------|------|--------|------|----------|------|---------------
ArrayList | O(1) | O(n) | O(1) | O(n) | O(1) | Array
LinkedList | O(1) | O(1) | O(n) | O(n) | O(1) | Linked List
CopyOnWriteArrayList | O(n) | O(n) | O(1) | O(n) | O(1) | Array
@rafsanahmad
rafsanahmad / EndlessRecyclerOnScrollListener.kt
Last active January 13, 2022 07:19
Smooth infinite scroll for Recyclerview for different layout managers, Kotlin Implementation
abstract class EndlessRecyclerOnScrollListener(
private val threshHold: Int = QUERY_PER_PAGE
) : RecyclerView.OnScrollListener() {
var isError = false
var isLoading = false
var isLastPage = false
var isScrolling = false
private var firstVisibleItem: Int = 0
private var visibleItemCount: Int = 0
@rafsanahmad
rafsanahmad / ImageVideoUtils.java
Created November 11, 2021 08:35
Image video Utility functions like handle rotation, resize, save bitmap, get size, metadata etc.
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.ContentResolver;
import android.content.Context;
import android.content.res.ColorStateList;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.Matrix;
@rafsanahmad
rafsanahmad / PasswordUtil.java
Created November 11, 2021 08:28
A utils for testing Password rule.
import java.util.regex.Pattern;
public class PasswordUtil {
private static String MsgLen8 = "String Must be 8 characters long";
private static String MsgUpper = "Must contain at least one upper case letter";
private static String MsgLower = "Must contain at least one lower case letter";
private static String MsgDigit = "Must contain at least one digit";
private static String MsgSp = "Must contain at least one special character from this list: !@#$%^&*()+-.,\"'(){}[]:;?/\\";
private static Pattern pattern = Pattern.compile("^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^&*()+=])(?=\\\\S+$).{4,}$");