Skip to content

Instantly share code, notes, and snippets.

View foyez's full-sized avatar
🎯
Focusing

Kazi Foyez Ahmed foyez

🎯
Focusing
View GitHub Profile
@foyez
foyez / linux-permissions.md
Created March 7, 2025 00:38
Linux File Permissions

Linux File Permissions

Every file and directory in Linux has permissions assigned to three categories:

  1. User (Owner): A user is the owner of the file. By default, the person who created a file becomes its owner.
  2. Group: A user- group can contain multiple users. All users belonging to a group will have the same Linux group permissions access to the file.
  3. Others: Any other user who has access to a file.

Each category has three types of permissions:

  • r (Read) → Can view the file contents
  • w (Write) → Can modify the file
@foyez
foyez / move-array-element-from-one-position-to-another.js
Last active September 28, 2022 07:15
Move an array element from one position to another
// Move array element using splice where time complexity is Quadratic Time - O(n^2)
function arrayMove(arr, oldIndex, newIndex) {
const copiedArr = [...arr];
const length = copiedArr.length;
if (oldIndex !== newIndex && length > oldIndex && length > newIndex) {
copiedArr.splice(newIndex, 0, copiedArr.splice(oldIndex, 1)[0]);
}
return copiedArr;
@foyez
foyez / set-cursor-range.js
Last active March 30, 2022 12:08
Set cursor position on clicked location in contenteditable
const getMouseEventCaretRange = (event, doc = document) => {
const x = event.clientX;
const y = event.clientY;
// IE
if (doc.body.createTextRange) {
const range = doc.body.createTextRange();
range.moveToPoint(x, y);
return range;
}
@foyez
foyez / nvm-with-fish-in-linux.md
Last active January 15, 2022 05:40
Step by step to setup nvm with linux and fish shell
  1. Update the package repository
sudo apt update
  1. Install NVM link
# using curl
@foyez
foyez / cancel-axios-request.js
Created October 12, 2021 02:34
Cancel a api reqest using fetch and axios in React
import React, {useState, useEffect} from 'react'
const Example = () => {
const [user, setUser] = useState(null)
const signal = axios.CancelToken.source()
useEffect(() => {
(async function loadUser(){
try {
const {data} = await axios.get('https://randomuser.me/api', {
@foyez
foyez / react.md
Last active January 21, 2022 07:04

React

React.memo

const Greeting = ({ name }) => <div>Hello, {name}</div>
const MemoizedGreeting = React.memo(Greeting)

When a component is wrapped in React.memo(), React renders the component and memoizes the result. Before the next render, if the new props are the same, React reuses the memoized result skipping the next rendering.

@foyez
foyez / linux-setup.md
Last active September 22, 2021 15:35

git

istall git:

sudo apt install git

curl

this

1. Global Context

console.log(this) // Window {postMessage: ƒ, blur: ƒ, focus: ƒ, close: ƒ, parent: Window, …}
function printThis() {
@foyez
foyez / dfs-bfs-implementation.js
Created January 4, 2021 07:23
BFS & DFS implementation in JS
const board = ['#####B#', '##### #', '#### #', '#### ##', ' ##', 'A######']
class Node {
constructor(state, parent, action) {
this.state = state
this.parent = parent
this.action = action
}
}
import React from 'react'
const UserProfile = ({ data }) => {
return (
<>
<h1>{data.name}</h1>
<h2>{data.email}</h2>
</>
)
}