Skip to content

Instantly share code, notes, and snippets.

View josephm28's full-sized avatar

Joseph Malone josephm28

View GitHub Profile
@josephm28
josephm28 / zsh.txt
Created March 3, 2021 21:14
oh-my-zsh notes
zsh-autosuggestions & zsh-syntax-highlighting
https://gist.github.com/dogrocker/1efb8fd9427779c827058f873b94df95
@josephm28
josephm28 / js-timing-example.js
Created December 1, 2020 14:38
JS timing example
const startTime = performance.now();
//Do stuff here to time it
const endTime = performance.now();
const diff = Math.ceil(endTime - startTime);
const milliseconds = diff;
console.log(`Code took ${milliseconds} ms`);
@josephm28
josephm28 / appflow-tips.md
Last active November 8, 2022 20:10
Appflow Build Tips - Excessive Memory Consumption

Appflow Build Tips - Excessive Memory Consumption

Update 7/24/2020

The ENOMEM and EPIPE and Terser errors are back and just as nasty as before. Here are some details on how to fix:

  1. Of course, update all Angular build related npm modules
  2. The biggest problem comes from this issue angular/angular-cli#18087 (comment) in copy-webpack-plugin (Fix: webpack-contrib/copy-webpack-plugin#507) which is included in Angular @angular-devkit/build-angular. This fix made it in this week (https://github.com/angular/angular-cli/releases/tag/v8.3.29)

Again, update your npm modules, especially Angular as those are critical.

@josephm28
josephm28 / console-todo.ts
Created December 6, 2019 13:57
Add todo method to console
console.todo = function(todo: string) {
var err = new Error();
console.log(`%c\tTODO\t${todo}\t\n`, 'background: #66ba6559; color: #046884');
console.groupCollapsed();
console.log(
err.stack
.split('\n')
.slice(0, 3)
.join('\n'),
);
@josephm28
josephm28 / load-stylesheet-if-not-loaded.js
Created March 18, 2019 12:55
Load CSS Stylesheet if it's not loaded already. This is incredibly helpful to include in your JS modules, right above the class, as a way of importing the CSS file for the module without having to track it all in the main html page.
function loadCSSSheetIfNotLoaded({url}){
//Get the current stylesheets
const currentStyles = Object.values(document.styleSheets);
const foundSheet = currentStyles.find(sheet => sheet.href ? sheet.href.indexOf(url) != -1 : false);
if(!foundSheet){
//Didn't find the stylesheet, so let's add it
$(`<link href="${url}" rel="stylesheet">`).appendTo("head");
}
}
@josephm28
josephm28 / promise-load-js.js
Created March 13, 2019 21:26
Dynamically load JS scripts in bulk. Wait for all scripts to be loaded
async loadJSScripts(){
return new Promise((resolve, reject)=>{
const scriptsToBeLoaded = [...];
await Proimise.all(
scriptsToBeLoaded.map(async script => await $.getScript(script))
);
resolve();
});
}
@josephm28
josephm28 / promise-load-css.js
Created March 13, 2019 21:22
Dynamically load CSS using JS, with a promise to know when the style has been loaded. Do it all in bulk
async loadCSSStyles(){
return new Promise((resolve, reject)=>{
const styleURLs = [...];
await Promise.all(styleURLs.map(async style => await fetchStyle(style)));
resolve();
})
})
const fetchStyle = (url) => {
//https://stackoverflow.com/questions/574944/how-to-load-up-css-files-using-javascript
return new Promise((resolve, reject) => {