Skip to content

Instantly share code, notes, and snippets.

View achrefabdennebi's full-sized avatar
🤟

ABDENNEBI achrefabdennebi

🤟
View GitHub Profile
@achrefabdennebi
achrefabdennebi / dom.service.ts
Created February 23, 2021 11:15 — forked from caroso1222/dom.service.ts
Service to dynamically append Angular components to the body
import {
Injectable,
Injector,
ComponentFactoryResolver,
EmbeddedViewRef,
ApplicationRef
} from '@angular/core';
@Injectable()
export class DomService {

List global installed packages

npm list -g --depth 0

Create SSH key

ssh-keygen -t rsa -b 4096 -C "[email protected]"

List SSH keys

ls ~/.ssh

Content SSH key

const AdmZip = require('adm-zip');
const rimraf = require("rimraf");
const processPath = process.cwd();
const packagesToExtract = [
{
name: 'angularEditor',
entries: null,
'#'+Math.floor(Math.random()*16777215).toString(16);
const promise1 = new Promise((resolve, reject) => resolve("Resolved promise1!"));
const promise2 = new Promise((resolve, reject) => reject("Rejected promise2!"));
const promise3 = new Promise((resolve, reject) => resolve("Resolved promise3!"));
const allPromises = [promise1, promise2, promise3];
Promise.all(allPromises).then((results) => {
//if all promises in the collection resolves, `results` is an array of [promise1 result, promise2 result, promise3 result]
}).catch((error) => {
//if any promise is rejected, `error` will have the rejected value of the promise that failed
//if multiple failed, `error` will be the error of the first one that failed
@achrefabdennebi
achrefabdennebi / Reduce_functions.js
Last active March 22, 2019 16:58
1- Arrays (GroupBy, KeyBy, Chunk, Flatten, FlatMap)
/*
Group list by property name
*/
function keyBy(list, key) {
return list.reduce((acc, item) => {
const index = item[key];
acc[index] = item;
return acc;
}, {});
}
const renamed = ({ ID, ...object }) => ({ id: ID, ...object })
const user = {
ID: 500,
name: "Bob Fossil"
}
renamed(user) //=> { id: 500, name: 'Bob Fossil' }
const user = { id: 100, name: 'Howard Moon' }
const password = 'Password!'
const userWithPassword = {
...user,
id: 100,
...(password && { password })
}
userWithPassword //=> { id: 100, name: 'Howard Moon', password: 'Password!' }
const setDefaults = ({ ...object}) => ({ quotes: [], ...object })
const user1 = {
id: 100,
name: 'Howard Moon',
password: 'Password!'
}
const removeProperty = prop => ({ [prop]: _, ...rest }) => rest
// ---- ------
// \ /
// dynamic destructuring