Skip to content

Instantly share code, notes, and snippets.

View tinncdev's full-sized avatar

Tin Nguyen tinncdev

  • Ho Chi Minh city
View GitHub Profile
@tinncdev
tinncdev / diff.ts
Last active August 3, 2021 04:51
categorize added/updated/deleted/unchanged items from 2 set
function diff<T>(
currentItems: T[],
newItems: T[],
identifier: (item: T) => any,
equalComparator: (item1: T, item2: T) => boolean,
): { added: T[], updated: T[], deleted: T[], unchanged: T[] } {
const added: T[] = [];
const updated: T[] = [];
const deleted: T[] = [];
const unchanged: T[] = [];
@tinncdev
tinncdev / toSnakeCase.js
Created July 26, 2021 10:02
A simple function to transform any string to snake case, skip all none alphanumberic characters
// A simple function to transform any string to snake case, skip all none alphanumberic characters
// Example: `NET WET. 0.09 g / 0.003 OZ.` will output `net_wet_0_09_g_0_003_oz`
const toSnakeCase = (text) => text.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g)
.map(x => x.toLowerCase())
.join('_');
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
public abstract class EndlessRecyclerOnScrollListener extends RecyclerView.OnScrollListener {
public static String TAG = EndlessRecyclerOnScrollListener.class.getSimpleName();
private int previousTotal = 0; // The total number of items in the dataset after the last load
private boolean loading = true; // True if we are still waiting for the last set of data to load.
private int visibleThreshold = 5; // The minimum amount of items to have below your current scroll position before loading more.
int firstVisibleItem, visibleItemCount, totalItemCount;