Skip to content

Instantly share code, notes, and snippets.

@sakshstore
sakshstore / array_merge.html
Created August 10, 2023 03:59
javascript array merge
<!doctype html>
<html lang="en" data-bs-theme="auto">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="Mark Otto, Jacob Thornton, and Bootstrap contributors">
<meta name="generator" content="Hugo 0.115.4">
<title>Heroes · Bootstrap v5.3</title>
@sakshstore
sakshstore / Array Destructuring .js
Created August 10, 2023 03:43
Array destructuring allows you to extract individual elements from an array and assign them to separate variables.
// Longhand
const numbers = [1, 2, 3];
const firstNumber = numbers[0];
const secondNumber = numbers[1];
// Shorthand
const numbers = [1, 2, 3];
const [firstNumber, secondNumber] = numbers;
@sakshstore
sakshstore / Destructuring Assignment .js
Created August 10, 2023 03:41
Destructuring assignment unpacks values from arrays or properties from objects into distinct variables, making it easier to work with complex data structures.
// Longhand
const person = { firstName: 'John', lastName: 'Doe' };
const firstName = person.firstName;
const lastName = person.lastName;
// Shorthand
const person = { firstName: 'John', lastName: 'Doe' };
const { firstName, lastName } = person;
@sakshstore
sakshstore / short function.js
Created August 10, 2023 03:39
For single expression functions, you can use arrow functions with implicit return for more concise code.
// Longhand
const multiply = (a, b) => {
return a * b;
};
// Shorthand
const multiply = (a, b) => a * b;
@sakshstore
sakshstore / find_array.js
Created August 10, 2023 03:38
The Array.find() and Array.findIndex() methods allow you to find elements in an array based on a condition.
// Longhand
const numbers = [1, 2, 3, 4, 5];
let foundNumber;
for (let i = 0; i < numbers.length; i++) {
if (numbers[i] > 3) {
foundNumber = numbers[i];
break;
}
}
@sakshstore
sakshstore / async_await .js
Last active August 10, 2023 03:38
async/await is a modern approach to handle asynchronous code, making it look more synchronous and easier to read.
// Longhand
function fetchData() {
return fetch('https://api.example.com/data')
.then((response) => response.json())
.then((data) => {
console.log(data);
})
.catch((error) => {
console.error(error);
});
@sakshstore
sakshstore / .angular-htaccess.md
Created May 23, 2023 05:28 — forked from julianpoemp/.angular-htaccess.md
Optimal .htaccess configuration for Angular 15, Angular 14, Angular 13, Angular 12, Angular 11, Angular 10, Angular 9, Angular 8, Angular 7, Angular 6, Angular 5 (and older) app in production incl. fix for the angular browser caching issue.

New generator

I created a new htaccess generator for angular apps that makes it easier for you to create the optimal htaccess file: https://julianpoemp.github.io/ngx-htaccess-generator/

The goal of this generator is to create the optimal .htaccess file for Angular apps easily. By default the generator creates an .htaccess file that solves the route redirection issue. To make it easier for you I created a kind of interview mode with some questions. As an additional feature the generator supports adding exclusions for example if you have installed a blog in a subdirectory of your web application and more!

The generator 😁: https://julianpoemp.github.io/ngx-htaccess-generator/

The project: https://github.com/julianpoemp/ngx-htaccess-generator

const copyToClipboard = (text) =>
navigator?.clipboard?.writeText(text) ?? false;
// Usage
copyToClipboard("Hello World!");
const getQueryParams = (url) => new URLSearchParams(url.split("?")[1]);
// Usage
getQueryParams("https://example.com?a=1&b=2"); // { a: "1", b: "2" }
const getSelectedText = () => window.getSelection().toString();
// Usage
getSelectedText(); // Selected text