Skip to content

Instantly share code, notes, and snippets.

View kaleem-elahi's full-sized avatar
🏡
Work From Home chal raha hai !

Kaleem Elahi Shaikh kaleem-elahi

🏡
Work From Home chal raha hai !
View GitHub Profile
@kaleem-elahi
kaleem-elahi / sortAll.js
Last active July 16, 2018 14:34
A Sorting function that sorts Letters and Numbers both in ascending order (Made for React)
export function sortAll(arr, key = 'key', direction = 'asc', type = 'string') {
return arr.sort((a, b) => {
let keyA;
let keyB;
if (type === 'string') {
keyA = a[key].toLowerCase();
keyB = b[key].toLowerCase();
}
if (type === 'number') {
keyA = parseInt(a[key], 2);
@kaleem-elahi
kaleem-elahi / getMultiSortedValues.js
Last active July 16, 2018 14:37
sorting data with string and number in object
export const getMultiSortedValues = (arr, key, num) =>
arr.sort((a, b) => {
if (a[num] === b[num]) return a[key].localeCompare(b[key]);
return b[num] - a[num];
});
@kaleem-elahi
kaleem-elahi / validators.js
Created July 16, 2018 14:38
Validation for react
import moment from 'moment';
export const email = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
export const specialCharactersRegex = /^[0-9a-zA-Z _-]{1,30}$/;
export const required = value => (!value ? 'Required' : undefined);
export const isEqual = (value, compareValue) => (value === compareValue);
@kaleem-elahi
kaleem-elahi / MultiSelect.js
Created August 21, 2018 07:24
Logic on react-select for material-ui redux-form field. Supports for Async, Async-Creatable, Creatable & Normal one with single as well as milti-select
import React from 'react';
import Select from 'react-select';
import PropTypes from 'prop-types';
import 'react-select/dist/react-select.css';
import BASE_URL from '../../constants';
const SelectType = (type, props, asyncProps) => {
const {
searchKey,
@kaleem-elahi
kaleem-elahi / Api.js
Created August 21, 2018 10:56
API manager
import axios from 'axios';
import BASE_URL from './../constants';
import {
showNotification,
} from '../utils/Notifications';
function makeHeaders() {
let headerObj = {};
if (JSON.parse(localStorage.getItem('user_info')) != null) {
@kaleem-elahi
kaleem-elahi / configStore.js
Created August 21, 2018 11:00
redux-promise-middleware
// This file merely configures the store for hot reloading.
// This boilerplate file is likely to be the same for each project that uses Redux.
// With Redux, the actual stores are in /reducers.
import promiseMiddleware from 'redux-promise-middleware';
import { createStore, applyMiddleware, compose } from 'redux';
import thunkMiddleware from 'redux-thunk';
import rootReducer from './';
@kaleem-elahi
kaleem-elahi / reducer.js
Created August 25, 2018 11:21
An example reducer file for react and also shows how to use redux-promise-middleware
import * as actionTypes from './actionTypes';
const initialState = {
customers: [],
searchItem: '',
totalCustomers: 0,
currentPageNo: 1,
currentPageSize: 100,
selectedUsers: [],
loading: false,
@kaleem-elahi
kaleem-elahi / FormInput.js
Created September 5, 2018 05:49
Material-ui's Textfield
/*
<Input
type={String}
label={String}
placeholder={String}
name={String}
value={String}
onFocus={function}
onChange={function}
@kaleem-elahi
kaleem-elahi / change-favicon.js
Created October 1, 2018 11:40 — forked from mathiasbynens/change-favicon.js
Dynamically changing favicons with JavaScript
/*!
* Dynamically changing favicons with JavaScript
* Works in all A-grade browsers except Safari and Internet Explorer
* Demo: http://mathiasbynens.be/demo/dynamic-favicons
*/
// HTML5™, baby! http://mathiasbynens.be/notes/document-head
document.head || (document.head = document.getElementsByTagName('head')[0]);
function changeFavicon(src) {
@kaleem-elahi
kaleem-elahi / media-query.css
Created November 27, 2018 12:27 — forked from gokulkrishh/media-query.css
CSS Media Queries for Desktop, Tablet, Mobile.
/*
##Device = Desktops
##Screen = 1281px to higher resolution desktops
*/
@media (min-width: 1281px) {
//CSS