Skip to content

Instantly share code, notes, and snippets.

View 3imed-jaberi's full-sized avatar
🎯
Focusing

Imed Jaberi 3imed-jaberi

🎯
Focusing
View GitHub Profile
// npm i express
const os = require('os');
const express = require('express');
const app = express();
const getNetworkIPAddress = () =>
os.networkInterfaces().WiFi.find((wifi) => wifi.family === 'IPv4').address;
const PORT = 3000;
const APP_URL = `http://${getNetworkIPAddress()}:${PORT}`;
const STATIC_DIRECOTY = 'public';
@3imed-jaberi
3imed-jaberi / esm-package.md
Created December 8, 2021 23:09 — forked from sindresorhus/esm-package.md
Pure ESM package

Pure ESM package

The package linked to from here is now pure ESM. It cannot be require()'d from CommonJS.

This means you have the following choices:

  1. Use ESM yourself. (preferred)
    Use import foo from 'foo' instead of const foo = require('foo') to import the package. You also need to put "type": "module" in your package.json and more. Follow the below guide.
  2. If the package is used in an async context, you could use await import(…) from CommonJS instead of require(…).
  3. Stay on the existing version of the package until you can move to ESM.
@3imed-jaberi
3imed-jaberi / variadic_functions_in_c.c
Created December 1, 2021 23:46
Variadic functions in C lang
// ########################### //
// # Variadic functions in C # //
// ########################### //
/**
* Variadic functions are functions that can take a variable number of arguments.
* It's like spread op. all arguments in function signature in JavaScript.
*/
// ################################################################################# //

Semantic Commit Messages

See how a minor change to your commit message style can make you a better programmer.

Format: <type>(<scope>): <subject>

<scope> is optional

Example

@3imed-jaberi
3imed-jaberi / nan-result-for-array-mapped-by-parseInt-solution.js
Created November 29, 2021 23:11
Why ['1', '7', '11'].map(parseInt) returns [1, NaN, 3] in Javascript.
/**
* ['1', '7', '11'].map(parseInt) doesn’t work as intended because map passes
* three arguments into parseInt() on each iteration. The second argument
* index is passed into parseInt as a radix parameter. So, each string in the array
* is parsed using a different radix. '7' is parsed as radix 1, which is NaN,
* '11' is parsed as radix 2, which is 3. '1' is parsed as the default radix 10,
* because its index 0 is falsy.
*
* And so, the following code will work as intended;
*/
@3imed-jaberi
3imed-jaberi / query-string.parse.js
Created November 29, 2021 13:20
implementation of query-string parse.
// implementation of querystring parse.
const queryStringDotParse = (str = '') =>
str.split('&').reduce((parsedObject, param) => {
if (param === '') return parsedObject
const [key, value] = param.split('=')
parsedObject[key] = decodeURIComponent(value)
return parsedObject
}, {})
@3imed-jaberi
3imed-jaberi / useCombineReducer.js
Created August 8, 2021 23:46
useCombineReducer - Helper Hook for React.js
/**
* @title useCombineReducers Hook
* @description Custom hook to combine all useReducer hooks for one global state container with
* one dispatch function. Use at top-level and pass dispatch function (and state) down
* via React's Context API with Provider and Consumer/useContext.
*/
// --------------------------- Source Code --------------------------- //
/**
@3imed-jaberi
3imed-jaberi / Input.js
Created July 24, 2021 14:13
React testing support for formalab course
import React, { useState } from 'react'
function Input({ setTodos, todos }) {
// define the local state
const [todo, setTodo] = React.useState('')
// define the onChange handler
const handleChange = (event) => setTodo(event.target.value)
// define the addTodo handler
const addTodo = () => {
// check that exist todo
@3imed-jaberi
3imed-jaberi / LightRequest.ts
Last active May 9, 2020 00:19
Lightweight HTTP/HTTPS client for Node.js 🔥. Make request easy with pure modules ✨.
// ************************************************
// I was thinking about publish this package to
// npm, but I saw that's not necessary to do
// that, especially we have many wonderful pckgs
// that do the same thing.
// Like: Axios / GOT / Fetch implementations ..
// So, i want to share this code with community.
// ************************************************
import * as path from 'path';