Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View yakuzaaaa's full-sized avatar
🎯
Focusing

Nilarnab Mookherjee yakuzaaaa

🎯
Focusing
View GitHub Profile
@yakuzaaaa
yakuzaaaa / GenericRecylcerViewCursorAdapter.java
Created August 7, 2016 06:16
A cursor adapter implementation for recycler views in android
import android.database.Cursor;
import android.database.DataSetObserver;
import android.support.v7.widget.RecyclerView;
/**
* Created by nilarnab on 7/8/16.
*/
public abstract class GenericRecyclerViewCursorAdapter<Vh extends RecyclerView.ViewHolder> extends RecyclerView.Adapter<Vh> {
private Cursor mCursor;
private DataSetObserver mDataSetObserver;
@yakuzaaaa
yakuzaaaa / LemonadeCardview.java
Last active August 11, 2016 11:12
ModifiedCardViewCompat which removes dynamically the extra content padding added to cardviews in android on pre-lollipop devices
import android.content.Context;
import android.support.v7.widget.CardView;
import android.util.AttributeSet;
import android.view.ViewGroup;
public class LemonadeCardView extends CardView {
public LemonadeCardView(Context context) {
super(context);
init();
@yakuzaaaa
yakuzaaaa / colors.xml
Created August 21, 2016 10:50
A whole bunch of material design colors. This file is added so that a lot of boiler plate can be avoided.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="white">#FFFFFFFF</color>
<color name="black">#FF000000</color>
<!--reds-->
<color name="material_red_50">#FFEBEE</color>
<color name="material_red_100">#FFCDD2</color>
<color name="material_red_200">#EF9A9A</color>
import android.content.Context;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.util.AttributeSet;
import android.view.View;
public class FABMoveWithSnackBarBehaviour extends CoordinatorLayout.Behavior<FloatingActionButton> {
@yakuzaaaa
yakuzaaaa / introrx.md
Created March 20, 2017 09:57 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing
@yakuzaaaa
yakuzaaaa / dummy.js
Last active February 21, 2019 11:35
Code snippet in the lazy loading images blog by Adrobit Technologies
const image = document.getElementById('lazy-image');
image.src = image.dataset.src;
/*
A very inefficient but with best browser support way would be to check if the
clientBoundingRect of the image is currently inside the viewport or not on every
scroll event, damn! it's costly!
*/
/*
Let's say the images in HTML are:
document.addEventListener("DOMContentLoaded", function() {
const images = [].slice.call(document.querySelectorAll("lazy-image"));
if ("IntersectionObserver" in window) {
/**
We first check if API in available and then continue to create a simple IntersectionObserver
*/
let lazyImageObserver = new IntersectionObserver((entries, observer) => {
entries.forEach(function(entry) {
if (entry.isIntersecting) {
let image = entry.target;
<!--
We will use the directive in HTML in the following way
lazy-load here is our directive name and source is our input to the directive and it contains the original source URL -->
<img lazy-load [source]="srcUrl">
import { Directive, ElementRef, Input, OnChanges, SimpleChanges } from '@angular/core';
@Directive({
selector: '[lazy-load]' // Attribute selector
})
export class LazyLoadDirective implements OnChanges {
@Input('source')
source;
lazyImageObserver: any;