Skip to content

Instantly share code, notes, and snippets.

View adeelibr's full-sized avatar
🥋
doing bat shit crazy stuff with code

Adeel Imran adeelibr

🥋
doing bat shit crazy stuff with code
View GitHub Profile
@adeelibr
adeelibr / feature.flag.js
Created April 24, 2023 18:08
Proposal for feature flags
// BE does the feature flags for users for A/B testing
<FeatureFlag isEnabled={flagValue}>
// Content for a specific feature flag
</FeatureFlag>
const FeatureFlag = ({ isEnabled, children }) => {
return isEnabled ? children : null;
}
@adeelibr
adeelibr / magic.js
Created June 30, 2020 20:35
require.cache
const path = require('path')
const libPath = path.join(require.resolve('./my-library/another'), '..')
// console.log('libPath :: ', libPath)
const anotherPath = path.join(libPath, 'another')
const another = require(anotherPath)
// console.log('anotherPath ::', anotherPath)
// console.log('another ::', another)
@adeelibr
adeelibr / install-node.md
Last active June 22, 2020 19:54
How to install Node via NPM

Installation guide for Mac OS & Linux

Open your terminal & type

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash

Close your terminal & reopen a new one & type

@adeelibr
adeelibr / cypress-persist-user.js
Created November 26, 2019 12:22
Persist Login Between Tests In Cypress
before(() => {
cy.clearInfo();
cy.login();
});
after(() => {
cy.contains('Logout').click();
cy.contains('Login');
});
beforeEach(() => {
@adeelibr
adeelibr / closure-example.js
Created November 25, 2019 23:04
Closure video example youtube
// ignore this line, this is just here
// to clear console, everytime I hit "Run with JS"
console.clear();
// Comment out each example one by one & play with
// it, happy coding :)
// @example NOT* a closure example
// function person() {
// let name = 'adeel';
// ### EXAMPLE 1
// -- what you type
// var name = 'adeel';
// var profession = 'developer';
// console.log(name + ' ' + profession);
// -- what the machine does
// var name; // undefined
// var profession; // undefined;
// name = 'adeel';
@adeelibr
adeelibr / array-tutorial.js
Created November 17, 2019 21:42
Understanding javascript array methods like filter, map, some, every, reduce
// Understanding array methods:-
// - filter
// - map
// - some
// - every
// - reduce
let myOrgArray = [1,2,3, 4, 5, 6, 7, 8, 9, 10];
// Discussing array by reference
@adeelibr
adeelibr / use-scripts-documentation.md
Last active July 11, 2019 11:37
create-react-app --use-script

--use-script

How to provide file paths

There are multiple ways, but all of them start from here react-scripts

By default when you do

npx create-react-app my-app

@adeelibr
adeelibr / useIgnore.jsx
Last active October 1, 2019 06:32
A "hacky" approach to use instead of AbortControllers
/**
* @description Hacky implementation for ignoring
* @param {Function} callback
* @param {Array of primitive dependencies} deps, because
* Arrays & Objects don't work in useEffect deps
*/
const useIgnore = (callback, deps) => {
const [{success, error, loading}, setState] = React.useState({
success: null,
error: null,
@adeelibr
adeelibr / createPdf.js
Last active June 15, 2020 08:53
createPdf.js script for NodeJS FS & Puppeteer
const fs = require('fs');
const puppeteer = require('puppeteer');
// Build paths
const { buildPathHtml, buildPathPdf } = require('./buildPaths');
const printPdf = async () => {
console.log('Starting: Generating PDF Process, Kindly wait ..');
/** Launch a headleass browser */
const browser = await puppeteer.launch();
/* 1- Ccreate a newPage() object. It is created in default browser context. */