Skip to content

Instantly share code, notes, and snippets.

View Munawwar's full-sized avatar
🍪
Cookies

Munawwar Firoz Munawwar

🍪
Cookies
View GitHub Profile
@Munawwar
Munawwar / object-recursion.js
Last active April 5, 2020 09:09
Template for recursively traversing and transforming an object
const { isPlainObject } = require('lodash');
function objectRecursionAndTransformationTemplate(obj) {
if (!obj || !(isPlainObject(obj) || Array.isArray(obj))) {
// put your primitive val transformations here
return obj;
}
if (Array.isArray(obj)) {
// put your array transformations here
return obj.map(objectRecursionAndTransformationTemplate);
@Munawwar
Munawwar / axios-auto-cancel.js
Last active February 18, 2021 13:38
Axios call that aborts/cancels the previous call automatically
const postAndCancelPrevCall = (() => {
let cancelTokenInstance;
return async (body) => {
try {
if (cancelTokenInstance) {
cancelTokenInstance.cancel('cancelled by user');
}
cancelTokenInstance = CancelToken.source();
const axiosResponse = await axios.post(body, {
cancelToken: cancelTokenInstance.token
@Munawwar
Munawwar / daisy-chain.js
Last active July 13, 2021 11:51
Lodash chaining without importing the entire library
function chain(value) {
return {
/**
* @param {function|string} func function or function name (in chained value)
* @param {...any} args
*/
fn(func, ...args) {
if (typeof func === 'string') {
return chain(value[func](...args));
}
@Munawwar
Munawwar / cloud-machines-benchmarks.md
Last active August 21, 2020 07:22
Cloud machines benchmarks

sysbench --test=cpu --cpu-max-prime=20000 run

(all ubuntu 16)

Summary (95 percentile)

Scaleway DEV1-S = 2.40ms
Scaleway VC1M = 2.51ms
Scaleway VC1S = 2.56ms
Local Machine (Mackbook Pro 2015) = 2.66ms
@Munawwar
Munawwar / ridiculous-chaining.js
Last active July 3, 2020 17:28
Lodash-like chaining using reduce for Absurdum. Why? Cuz we can..
// Law of Absurd Reduces: Everything that can be implemented with reduce() will eventually be implemented with reduce()
/**
* @param {Object} chainableFunctions object where each key is the name of a function and it's value is the function itself
*/
const createChainables = (chainableFunctions) => ({
chain(initialValue) {
const operations = [];
const evaluate = () => operations.reduce(
(value, [func, ...args]) => func(value, ...args),
@Munawwar
Munawwar / README.md
Last active July 25, 2020 13:43
Functions only UI POC

A framework that lets you write your entire UI

  • as functions
  • with React hooks
  • without React
  • without classes
  • without vDOM/DOM diffing
  • without web components
  • without build step
@Munawwar
Munawwar / neverland-test.html
Last active July 26, 2020 13:10
Testing function-based framework neverland
<html lang="en">
<head>
<script src="https://unpkg.com/[email protected]/min.js"></script>
</head>
<body>
<div id="app1"></div>
<div id="app2"></div>
<script type="module">
const { neverland: $, render, html, useState } = neverland;
@Munawwar
Munawwar / global-state-manager.html
Created July 26, 2020 19:56
global state manager for neverland/uland
<html lang="en">
<head>
<script src="https://unpkg.com/[email protected]/min.js"></script>
<script>
const { useState, useEffect } = neverland;
const globalStateManager = (() => {
// "The" global store
let store = {};
// internal publisher-subscriber system to
@Munawwar
Munawwar / placeholder.html
Last active June 12, 2021 18:23
Create an artistic svg placeholder for an image (node.js)
<!-- the blur filter makes it look more like a placeholder than a final image -->
<img src="./output.svg" style="width: 1200px; filter: blur(5px)" />
@Munawwar
Munawwar / zustand-usage.js
Last active October 25, 2020 06:22
Zustand state manager usage
import create, { State, StateSelector } from 'zustand';
// initialization
const initialStates = { count: 0 }; // no need to add your actions here like how zustand README shows.
const useStore = create(() => initialStates);
const { getState, setState } = useStore;
// usage within function component (reactive)
const Component = () => {
const count = useStore(state => state.count);