Dev Dastan
324 subscribers
49 photos
2 videos
41 links
πŸ”Έ Programming Tips and Concepts πŸ‘Ύ

πŸ”ΉContact: @Hossein13M 🀘🏻
Download Telegram
πŸ“± Promise.all vs Promise.allSettled


πŸ•― Promise.all and Promise.allSettled are two methods provided by JavaScript's Promise API, but they have different behaviors and use cases.

πŸ”£ Promise.all
Waits for all promises to resolve or rejects immediately if any promise rejects. Resolves with an array of resolved values.


πŸ”£ Promise.allSettled
Waits for all promises to settle (resolve or reject) and always resolves. Returns an array of objects representing the outcomes of the promises, including their status and value/reason.


βž–βž–βž–βž–βž–βž–
πŸ“š Article: [here]
πŸ“± YouTube Video: [here]
πŸ“± Image Credit (on X.com): [here]
βž–βž–βž–βž–βž–βž–
#JavaScript


πŸ–₯ Follow @devDastan for more content.
Please open Telegram to view this post
VIEW IN TELEGRAM
❀8πŸ‘3
πŸ› API Architecture Style


πŸ—£οΈ Architecture styles define how different components of an API interact with one another. As a result, they ensure efficiency, reliability, and ease of integration with other systems by providing a standard approach to designing and building APIs.

πŸ—£οΈ You can check out the different types of API architecture styles in the attached image.


βž–βž–βž–βž–βž–βž–
πŸ“š Article: [here]
πŸ“± YouTube Video: [here]
βž–βž–βž–βž–βž–βž–
#systemDesign #api


πŸ–₯ Follow @devDastan for more content.
Please open Telegram to view this post
VIEW IN TELEGRAM
❀9πŸ‘5
🟦 TypeScript Tips and Tricks Series (Part 1)

πŸ”£ Template Literal Types:

Build complex string types using dynamic expressions within backticks.


type Endpoint = `/users/${number}`;

const validEndpoint: Endpoint = '/users/123';

// const invalidEndpoint: Endpoint = '/posts/456'; // Error: Type '"/posts/456"' is not assignable to type 'Endpoint'


✨ Use Case:
representing API responses, URL patterns, or validation formats.

βž–βž–βž–βž–βž–βž–
#TypeScript


πŸ–₯ Follow @devDastan for more content.
Please open Telegram to view this post
VIEW IN TELEGRAM
πŸ‘7❀3
πŸ“± JavaScript Quiz

⁉️ What's the value of num?

const num = parseInt('7*6', 10);


πŸ”€ 42
πŸ”€ "42"
πŸ”€ 7
πŸ”€ NaN

βœ”οΈ Answer:
parseInt returns only the first number in the string. Depending on the radix (the second argument specifying the number type: base 10, hexadecimal, octal, binary, etc.), parseInt validates the characters in the string. If it encounters an invalid character, it stops parsing and ignores the rest.

For example, in "78", only "7" is valid, so it parses it into the decimal 7, ignoring the "" and "8". Thus, num now equals 7.


βž–βž–βž–βž–βž–βž–
#JavaScript #Quiz


πŸ–₯ Follow @devDastan for more content.
Please open Telegram to view this post
VIEW IN TELEGRAM
πŸ‘8🀯5
πŸ–ΌοΈ React State vs Refs


πŸ”£ State: For data that changes the UI. Updates trigger re-renders.

import { useState } from 'react';

function Counter() {
const [count, setCount] = useState(0);

return (
<div>
<p>You clicked {count} times</p>
<button onClick={() => setCount(count + 1)}>Click me</button>
</div>
);
}


πŸ”£ Refs: For directly accessing DOM elements or storing mutable values. Don't trigger re-renders.

import { useRef } from 'react';

function InputFocus() {
const inputRef = useRef(null);

function handleFocus() {
inputRef.current.focus();
}

return (
<div>
<input ref={inputRef} />
<button onClick={handleFocus}>Focus Input</button>
</div>
);
}


✨ Keep in mind that:

- State is immutable
- Avoid reading/writing refs during rendering
- Both persist data and have different update behaviors

βž–βž–βž–βž–βž–βž–
πŸ“š Article: [here]
βž–βž–βž–βž–βž–βž–
#JavaScript #ReactJS


πŸ–₯ Follow @devDastan for more content.
Please open Telegram to view this post
VIEW IN TELEGRAM
πŸ‘11😎1
🟦 TypeScript Tips and Tricks Series (Part 2)

❀ Read Previous Parts: [part 1]

πŸ”£ Higher-Order Types (HOT):

Utilize functions that take and return types, enabling powerful abstractions like generic type predicates and type builders.


type IsStringLiteral<T> = T extends string ? true : false;

function logIfString<T>(value: T): T extends string ? void : T {
if (IsStringLiteral<T>) {
console.log(value);
}
return value;
}


✨ Use Case:
Creating dynamic component that have multiple states and behaviors.

βž–βž–βž–βž–βž–βž–
#TypeScript


πŸ–₯ Follow @devDastan for more content.
Please open Telegram to view this post
VIEW IN TELEGRAM
πŸ‘6❀3
πŸ“± JavaScript Quiz

⁉️ What's the output?

const user = {
email: "[email protected]",
updateEmail: email => {
this.email = email;
}
}

user.updateEmail("[email protected]")
console.log(user.email)


πŸ”€ [email protected]
πŸ”€ [email protected]
πŸ”€ undefined
πŸ”€ ReferenceError

βœ”οΈ Answer:
The updateEmail function is an arrow function, and is not bound to the user object. This means that the this keyword is not referring to the user object, but refers to the global scope in this case. The value of email within the user object does not get updated. When logging the value of user.email, the original value of [email protected] gets returned.

βž–βž–βž–βž–βž–βž–
#JavaScript #Quiz


πŸ–₯ Follow @devDastan for more content.
Please open Telegram to view this post
VIEW IN TELEGRAM
πŸ‘9🀯5❀4
✨ Software Engineering Quote

πŸ’¬ Programs must be written with the idea that they will be read by people, and only incidentally for machines to execute.

πŸ”£ Harold Abelson

βž–βž–βž–βž–βž–βž–
#Agile #softwareEngineering

πŸ–₯ Follow @devDastan for more content.
Please open Telegram to view this post
VIEW IN TELEGRAM
❀9πŸ‘5
πŸ–ΌοΈ CSS Selectors Cheat Sheet

πŸ”£ At its core, CSS is about selecting elements from the DOM to apply styles to them.

✨ Child and Sibling Combinators (+ , ~, >)

/* Child combinator: selects direct children of an element */
.parent > .child {
color: red;
}


✨ Pseudo-Classes (:nth-child(), :nth-of-type(), :not(), :focus, :hover):

.faq-item:nth-of-type(odd) .faq-question{
background-color: #fff; /* For odd items
*/
}


✨ Structural Pseudo-Classes (:first-child, :last-child, :empty, :only-child):

.faq-item:first-of-type .faq-question {
border-top: 2px solid #007BFF;
}


✨ Pseudo-Elements (::before, ::after, ::first-letter, ::first-line):

/* ::after used to display "+" symbol */
.faq-question::after {
content: '+';
color: #00ad8f;
font-size: 1.4em;
}


✨ Attribute Selectors ( [attr^="value"], [attr$="value"], [attr*="value"]):

.faq-item[data-category^="important"] .faq-question {
color: #E91E63;
}


βœ”οΈ We will learn more about the use case of each CSS selector in advance later!

βž–βž–βž–βž–βž–βž–
πŸ“š Article: [here]
πŸ“± Image Credit: [here]
βž–βž–βž–βž–βž–βž–
#css


πŸ–₯ Follow @devDastan for more content.
Please open Telegram to view this post
VIEW IN TELEGRAM
πŸ‘6🀯3❀2😎1
🟦 TypeScript Tips and Tricks Series (Part 3)

❀ Previous Parts: [part 1 | Part 2]

πŸ”£ Conditional Types:

Shape types based on conditions, creating dynamic type hierarchies. For example, defining a type that’s an object with specific properties depending on a provided string value.


type Config = {
type: 'basic' | 'advanced';
};

type BasicConfig = Config & { type: 'basic' };
type AdvancedConfig = Config & { type: 'advanced' };

function configure(config: Config): void {
if (config.type === 'basic') {
console.log('Applying basic configuration');
} else {
console.log('Applying advanced configuration');
}
}


✨ Use Case:
Useful for strategy patterns and implementing high-level business logic.

βž–βž–βž–βž–βž–βž–
#TypeScript


πŸ–₯ Follow @devDastan for more content.
Please open Telegram to view this post
VIEW IN TELEGRAM
πŸ‘8❀5🀯2😎1
πŸ” Best Practices For Building Secure FrontEnd Applications

❀ Read Previous Parts: [OSI Layers Review | Common Security Attacks]

βœ”οΈ Cultivate a security-focused culture
πŸ”Έ Involve all stakeholders in mapping security risks and protections.
πŸ”Έ Develop a strong security culture affecting daily procedures and offerings.

βœ”οΈ Implement Input/Output Sanitization Strategy
πŸ”Έ Validate incoming data at each application stage.
πŸ”Έ Use libraries like dom-purify for quicker security implementation.
πŸ”Έ Refer to OWASP cheat sheet series for input/output sanitization.

βœ”οΈ Regularly examine components and execute a Content Security Policy (CSP)
πŸ”Έ Use Software Composition Analysis (SCA) for third-party library security.
πŸ”Έ Implement Content-Security-Policy (CSP) for front-end security.

We will learn more about the tools we can use to check our website's security!

βž–βž–βž–βž–βž–βž–
πŸ“š Article: [here]
βž–βž–βž–βž–βž–βž–
#network #security


πŸ–₯ Follow @devDastan for more content.
Please open Telegram to view this post
VIEW IN TELEGRAM
πŸ‘11❀3
πŸ‘¨β€πŸ’» Best Practices for Code Review


πŸ—£οΈ Review fewer than 400 lines of code at a time

πŸ—£οΈ Take your time. Inspection rates should under 500 LOC per hour

πŸ—£οΈ Foster a positive code review culture

βž–βž–βž–βž–βž–βž–
πŸ“š Article: [here]
πŸ“± YouTube Video: [here]
βž–βž–βž–βž–βž–βž–
#softwareEngineering #softSkill


πŸ–₯ Follow @devDastan for more content.
Please open Telegram to view this post
VIEW IN TELEGRAM
πŸ‘11❀2😎1
✨ Software Engineering Quote

πŸ’¬ Code is like humor. When you have to explain it, it’s bad.

πŸ”£ Cory House

βž–βž–βž–βž–βž–βž–
#softwareEngineering #programming

πŸ–₯ Follow @devDastan for more content.
Please open Telegram to view this post
VIEW IN TELEGRAM
πŸ‘12🀯1🍌1
πŸ”Ί Code Review Pyramid

❀ Read Previous Parts: [Code Review Best Practices]

πŸ—£οΈ Each layer of Code Review Pyramid is a characteristic to which the reviewed code must conform.
The bottom layer is the correctness of the code, which is of prime importance.


1️⃣ Code Style
🟒 Consistent naming and formatting.
πŸ”˜ Avoid duplication and unused imports.
🟒 Use automatic code formatting tools.

2️⃣ Tests
🟒 Review test cases for coverage.
πŸ”˜ Automate testing using plugins.

3️⃣ Documentation
🟒 Keep documentation comprehensive and up-to-date.

4️⃣ Implementation Semantics
🟒 Ensure code meets requirements, is efficient, and secure.
πŸ”˜ Check for error handling, resource management, concurrency, and third-party libraries.
🟒 Avoid code smells and anti-patterns.

5️⃣ API Semantics
🟒 Ensure API design follows best practices and provides a clear interface.
πŸ”˜ Check for consistency, versioning, error messages, pagination, filtering, and performance.
🟒 Ensure no internal logic leakage, no breaking of existing API, and proper authentication/authorization.

⚠️ Code review shouldn’t proceed to upper layers until the bottom layer, correctness, gets approved.


βž–βž–βž–βž–βž–βž–
πŸ“š Article: [here]
πŸ₯³ Medium Article: [here]
βž–βž–βž–βž–βž–βž–
#softwareEngineering #softSkill


πŸ–₯ Follow @devDastan for more content.
Please open Telegram to view this post
VIEW IN TELEGRAM
πŸ‘8❀4🀯2
πŸ“± JavaScript Quiz

⁉️ What's the output?

const box = { x: 10, y: 20 };

Object.freeze(box);

const shape = box;
shape.x = 100;

console.log(shape);


πŸ”€ { x: 100 , y: 20 }
πŸ”€ { x: 10, y: 20 }
πŸ”€ { x: 100 }
πŸ”€ ReferenceError

βœ”οΈ Answer: πŸ”€
Object.freeze prevents adding, removing, or modifying properties of an object (unless the property’s value is another object).

When we create the variable shape and set it equal to the frozen object box, shape also refers to a frozen object. You can check if an object is frozen using Object.isFrozen. In this case, Object.isFrozen(shape) returns true.

Since shape is frozen and x is not an object, we cannot modify x. Therefore, x remains 10, and { x: 10, y: 20 } gets logged.


βž–βž–βž–βž–βž–βž–
#JavaScript #Quiz


πŸ–₯ Follow @devDastan for more content.
Please open Telegram to view this post
VIEW IN TELEGRAM
πŸ‘16😎2🀯1
πŸ–ΌοΈ Angular 18 Release Changes!


πŸ”£ Release Highlights:

βœ… Experimental support for zoneless change detection.
βœ… Angular.dev is the new home for Angular developers.
βœ… Material 3, deferrable views, built-in control flow are now stable.
βœ… Server-side rendering improvements: i18n hydration support, better debugging, event replay.

πŸ”£ Other Release Features:

βœ… Zoneless Change Detection
βœ… Native await for Zoneless Apps
βœ… Components Support Zoneless
βœ… Signal APIs in Developer Preview
βœ… Firebase App Hosting


βž–βž–βž–βž–βž–βž–
πŸ–ΌοΈ My LinkedIn Post With Full Details: [here]
πŸ₯³ Medium Article: [here]
πŸ–ΌοΈ YouTube Video: [here]
βž–βž–βž–βž–βž–βž–
#angular


πŸ–₯ Follow @devDastan for more content.
Please open Telegram to view this post
VIEW IN TELEGRAM
πŸ‘12❀1🀯1😎1
✨ Software Engineering Quote

πŸ’¬ Even the most complex systems are inherently simple when viewed from the right angle.

πŸ”£ Eliyahu M. Goldratt

βž–βž–βž–βž–βž–βž–
#softwareEngineering #systemDesign

πŸ–₯ Follow @devDastan for more content.
Please open Telegram to view this post
VIEW IN TELEGRAM
πŸ‘12❀1🀯1
🟦 TypeScript Tips and Tricks Series (Part 4)

❀ Previous Parts: [part 1 | Part 2 | Part 3]

πŸ”£ Mapped Types

Transform existing types by applying operations to each property. Useful for adding prefixes/suffixes to properties, creating key-value pairs from objects, etc.


interface User {
name: string;
age: number;
}

type ReadOnly<T> = { readonly [P in keyof T]: T[P] };

const readOnlyUser: ReadOnly<User> = {
name: 'Kurt',
age: 27
};

// readOnlyUser.name = 'Chester';
// Error: Cannot assign to 'name' because it is a read-only property


✨ Use Case:
Useful for manipulate and transform data from the API or before passing data to another component, with different data types.

βž–βž–βž–βž–βž–βž–
#TypeScript


πŸ–₯ Follow @devDastan for more content.
Please open Telegram to view this post
VIEW IN TELEGRAM
πŸ‘11❀2🀯1
πŸ–₯ Difference Between Encryption, Encoding, Hashing, Obfuscation


πŸ’¬ Encoding
βœ”οΈ Encoding is for maintaining data usability and can be reversed by employing the same algorithm that encoded the content, i.e. no key is used.


πŸ’¬ Encryption
βœ”οΈ Encryption is for maintaining data confidentiality and requires the use of a key (kept secret) in order to return to plaintext.


πŸ’¬ Hashing
βœ”οΈ Hashing is for validating the integrity of content by detecting all modification thereof via obvious changes to the hash output.


πŸ’¬ Obfuscation
βœ”οΈ Obfuscation is used to prevent people from understanding the meaning of something, and is often used with computer code to help prevent successful reverse engineering and/or theft of a product’s functionality.


βž–βž–βž–βž–βž–βž–
πŸ“š Article: [here]
πŸ₯³ Medium Article: [here]
πŸ–ΌοΈ YouTube Video: [here]
βž–βž–βž–βž–βž–βž–
#softwareEngineering #security


πŸ–₯ Follow @devDastan for more content.
Please open Telegram to view this post
VIEW IN TELEGRAM
πŸ‘18❀1
✨ Explaining Software Development Methods Comic

βž–βž–βž–βž–βž–βž–
πŸ“š Article: [here]
βž–βž–βž–βž–βž–βž–
#softwareEngineering #softwareDevelopment #comic

πŸ–₯ Follow @devDastan for more content.
Please open Telegram to view this post
VIEW IN TELEGRAM
πŸ‘8❀4🍌4😎1
βœ…οΈ Habits Of Great Software Engineers


1️⃣ Focusing beyond the code
As a developer you will code 20% of your time. You should excel at coding nonetheless, but it won't be enough to be great


2️⃣ Efficiency / Antifragility
Making sure everything around you runs smoothly and has forward momentum


3️⃣ Joy of tinkering
Build projects, try out frameworks, build stuff on the side. Keeps the spark alive


4️⃣ Knowing the why
It's important to know why your code does what it does, too many abstractions nowadays that rarely someone thinks below the level of their language e.g JS devs not thinking about the engine that runs their code


5️⃣ Thinking in systems
Knowing how your code impacts not only your individual system but other parts of the business/application/life


6️⃣ Tech detox
Recharging away from your monitor makes you a better programmer


7️⃣ The art of approximation
Knowing important tech numbers to approximate calculations when making decisions when programming


βž–βž–βž–βž–βž–βž–
πŸ“š Article: [here]
πŸ–ΌοΈ YouTube Video: [here]
βž–βž–βž–βž–βž–βž–
#softwareEngineering #softSkill


πŸ–₯ Follow @devDastan for more content.
Please open Telegram to view this post
VIEW IN TELEGRAM
πŸ‘10❀3🀯3