Skip to content

Instantly share code, notes, and snippets.

View muhammadfaizan's full-sized avatar

Muhammad Faizan muhammadfaizan

View GitHub Profile
@muhammadfaizan
muhammadfaizan / api.spec.js
Last active March 2, 2022 07:31
Mocking Axios Request
import test from 'ava'
import axios from 'axios'
import axiosMocker from './axios-mock'
import { externalAPI } from '../../services'
import qs from 'query-string'
const { addMock, enableMocking } = axiosMocker(externalAPI.request)
enableMocking(true)
test.serial('test getAccessToken', async t => {
@muhammadfaizan
muhammadfaizan / request.ts
Created February 24, 2022 08:19
Base Class Client Respository
import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios'
export class ResourcesRestClient {
private instance: AxiosInstance
private config?: AxiosRequestConfig
constructor(client: AxiosInstance, config?: AxiosRequestConfig) {
this.instance = client
this.config = config
@muhammadfaizan
muhammadfaizan / memorySizeOfObject.js
Created March 18, 2021 13:48
calculate memory size of javascript object, it is not a accurate value!
function memorySizeOf(obj) {
var bytes = 0;
function sizeOf(obj) {
if(obj !== null && obj !== undefined) {
switch(typeof obj) {
case 'number':
bytes += 8;
break;
case 'string':
@muhammadfaizan
muhammadfaizan / custom-errors.js
Last active February 16, 2023 17:07
A comprehensive utility for validation
/**
* Created by Muhammad Faizan on 7/12/2017.
*/
const ErrorFactory = (name, code) => class CustomError extends Error {
/**
*
* @param {Error|String} error
* @param {Object} options
* @param {String} options.errorCode
@muhammadfaizan
muhammadfaizan / resources.js
Created January 17, 2019 18:12
Creating Migrations with Bulk upload in mongoDB
require('dotenv').config()
const { MongoClient, ObjectID } = require('mongodb')
const url = process.env.MASTER_DB_URI
const documents = require('./data.json')
const connect = dbUrl => new Promise((resolve, reject) => {
MongoClient.connect(dbUrl, (err, db) => {
if (err) reject(err)
else resolve(db)
@muhammadfaizan
muhammadfaizan / base-schema.js
Created January 17, 2019 18:08
Defining Mongoose Schema
const mongoose = require('mongoose')
const RK = mongoose.Schema.ObjectId
module.exports = class BaseSchema extends mongoose.Schema {
constructor (schema) {
const updater = {
created: {
by: { type: String},
user: { type: RK, ref: 'User', select: false },
@muhammadfaizan
muhammadfaizan / README.md
Last active January 17, 2019 18:04
Creating dynamic routes in node.js (Express.js)

A bracket in file name is actually represent directory

@muhammadfaizan
muhammadfaizan / README.md
Last active January 15, 2019 13:56
Custom AWS Deployments using EC2

Custom AWS Deployments using EC2

In this talk, Mashhood share how we can configure "git push deployments". Using Git and EC2 we can quickly configure a deployment for our selves with minimal efforts. Then he also shares the deployment for S3 alongside this. Watch it on Youtube

Deployment Flow

  1. Create EC2 instance.
  2. Configure SSH alias
  3. Setup the instance
@muhammadfaizan
muhammadfaizan / gist:0ab8409e34a542a0040b2b79e2bb40f1
Created December 27, 2018 13:20
Gist to redirect app based on link
<script type="text/javascript">
(function() {
var appPath = '{{{appPath}}}';
var pageType = {
CART: '/cart/',
PRODUCT: '/d/',
CATALOG: '/c/',
WISHLIST: '/w/',
LOGIN: '/l/',
REGISTER: '/r/',
@muhammadfaizan
muhammadfaizan / expander.js
Created November 23, 2018 06:24
Script to expand through table and nested table.
function resetSeller(box, oldbox) {
var iconClassName = '.expander.class.name';
if (box === null) {
box = oldbox.parentElement;
console.log(box);
}
var expander = box.querySelector(iconClassName);
if (expander) {
expander.click();
setTimeout(() => {