Skip to content

Instantly share code, notes, and snippets.

View udittyagi's full-sized avatar

Udit Tyagi udittyagi

  • Bangalore, India
View GitHub Profile
const mediaQueryLists = {}; //Add all MediaQueryList object here.
const keys = Object.keys(queries);
const matches = {}; //contains initial query matches
keys.forEach(media => {
if (typeof queries[media] === 'string') {
/* Adding MediaQueryList object for each and every query to
mediaQueryLists object
*/
mediaQueryLists[media] = window.matchMedia(queries[media]);
import React from 'react';
import useBreakpoints from './_customHooks/useBreakpoint';
const App = (props) => {
const point = useBreakpoints();
return (
<div>
import {useState, useEffect} from 'react';
import throttle from 'lodash.throttle';
const getDeviceConfig = (width) => {
if(width < 320) {
return 'xs';
} else if(width >= 320 && width < 720 ) {
return 'sm';
} else if(width >= 720 && width < 1024) {
return 'md';
const getDeviceConfig = (width) => {
if(width < 320) {
return 'xs'
} else if(width >= 320 && width < 720 ) {
return 'sm'
} else if(width >= 720 && width < 1024) {
return 'md'
} else if(width >= 1024) {
return 'lg'
}
const fs = require('fs');
const readFileAsArray = (fileName, cb = () => {}) => {
return new Promise((resolve, reject) => {
if(typeof fileName !== 'string') {
process.nextTick(
cb,
new TypeError('Argument should be string')
)
return reject('Argument should be string')
const fs = require('fs');
const readFileAsArray = (fileName) => {
return new Promise((resolve, reject) => {
if(typeof fileName !== 'string') {
return reject('Argument should be string')
}
fs.readFile(fileName, 'utf8', (err, data) => {
if(err) {
101
102
103
104
105
106
const fs = require('fs');
const readFileAsArray = (fileName, cb) => {
if(typeof fileName !== 'string') {
return process.nextTick(
cb,
new TypeError('Argument should be string')
);
}
fs.readFile(fileName, 'utf8', (error, data) => {
const doSomething = (cb) => {
let a = Math.random() * 10;
if (a < 5) {
cb(new Error('Number is Too small'));
return;
}
cb(null, a);
};
function callback(error, data) {
console.log('main starting');
const a = require('./a.js');
const b = require('./b.js');
console.log('in main, a.done = %j, b.done = %j', a.done, b.done);