Skip to content

Instantly share code, notes, and snippets.

View ansarizafar's full-sized avatar

Zafar Ansari ansarizafar

View GitHub Profile
@ansarizafar
ansarizafar / 0_reuse_code.js
Created August 24, 2014 08:03
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@ansarizafar
ansarizafar / app.js
Created November 2, 2017 02:52 — forked from joshuataylor/app.js
Preact component to notify user when a change has been made, and on route change reload the page.
import { h, Component } from 'preact';
import { Router } from 'preact-router';
import Header from './header';
import Home from '../routes/home';
import Profile from '../routes/profile';
import NotifyChange from "./NotifyChange/index";
// import Home from 'async!../routes/home';
// import Profile from 'async!../routes/profile';
function isMobileDevice() {
return window.matchMedia('(hover: none) and (pointer: coarse)');
}
@ansarizafar
ansarizafar / svelte-observe.js
Created September 14, 2018 14:27 — forked from jacwright/svelte-observe.js
One `observe` for all svelte needs.
export function observe(key, callback, opts) {
const single = !Array.isArray(key);
const keypaths = single ? [ key ] : key;
const parts = keypaths.map(keypath => keypath.replace(/\[(\d+)\]/g, '.$1').split('.'));
const keys = parts.map(parts => parts[0]);
const fn = callback.bind(this);
let last = parts.map(parts => getNestedValue(this.get(), parts));
if (!opts || opts.init !== false) {
@ansarizafar
ansarizafar / svelte-observe.js
Created September 14, 2018 14:27 — forked from jacwright/svelte-observe.js
One `observe` for all svelte needs.
export function observe(key, callback, opts) {
const single = !Array.isArray(key);
const keypaths = single ? [ key ] : key;
const parts = keypaths.map(keypath => keypath.replace(/\[(\d+)\]/g, '.$1').split('.'));
const keys = parts.map(parts => parts[0]);
const fn = callback.bind(this);
let last = parts.map(parts => getNestedValue(this.get(), parts));
if (!opts || opts.init !== false) {
@ansarizafar
ansarizafar / svelte-observe.js
Created September 14, 2018 14:27 — forked from jacwright/svelte-observe.js
One `observe` for all svelte needs.
export function observe(key, callback, opts) {
const single = !Array.isArray(key);
const keypaths = single ? [ key ] : key;
const parts = keypaths.map(keypath => keypath.replace(/\[(\d+)\]/g, '.$1').split('.'));
const keys = parts.map(parts => parts[0]);
const fn = callback.bind(this);
let last = parts.map(parts => getNestedValue(this.get(), parts));
if (!opts || opts.init !== false) {
@ansarizafar
ansarizafar / requestIdleCallback.js
Created September 21, 2018 05:37 — forked from paullewis/requestIdleCallback.js
Shims rIC in case a browser doesn't support it.
/*!
* Copyright 2015 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@ansarizafar
ansarizafar / unregisterServiceWorkers.js
Created September 29, 2018 16:15 — forked from mrienstra/unregisterServiceWorkers.js
Unregister service workers, verbose
navigator.serviceWorker.getRegistrations().then(function (registrations) {
if (!registrations.length) {
console.log('No serviceWorker registrations found.')
return
}
for(let registration of registrations) {
registration.unregister().then(function (boolean) {
console.log(
(boolean ? 'Successfully unregistered' : 'Failed to unregister'), 'ServiceWorkerRegistration\n' +
(registration.installing ? ' .installing.scriptURL = ' + registration.installing.scriptURL + '\n' : '') +
@ansarizafar
ansarizafar / gradients.js
Created October 5, 2018 02:01 — forked from cossssmin/gradients.js
Tailwind CSS background-image gradients plugin
const _ = require('lodash');
module.exports = ({e, addUtilities, config}) => {
const gradients = config('gradients', [])
const variants = config('modules.gradients')
const gradientUtilities = _.map(gradients, (colors, name) => {
if (!_.isArray(colors)) {
colors = ['transparent', colors];
}
@ansarizafar
ansarizafar / main.css
Created December 11, 2018 14:33 — forked from abhishekjakhar/main.css
HTML Tables CSS File
*, *:before, *:after {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
body {
font-family: 'Lato', sans-serif;
color: #333;
font-weight: 400;