Skip to content

Instantly share code, notes, and snippets.

View bobdobbalina's full-sized avatar

Mike Grunwald bobdobbalina

View GitHub Profile
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
var homePage = Model.Content.Site();
}
@helper RenderChildPages(IEnumerable<IPublishedContent> pages)
{
if (pages.Any())
{
<ul>
{
"scripts": [],
"showConsole": true,
"template": true
}
@bobdobbalina
bobdobbalina / Chrome Remote Debugging
Created May 21, 2020 21:16
Mac Terminal command to open Chrome in remote debugging mode
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222
@bobdobbalina
bobdobbalina / parameter-validation.js
Created June 3, 2020 13:48
Javascript: Parameter Validation
const isRequired = () => { throw new Error('param is required'); };
const print = (num = isRequired()) => { console.log(`printing ${num}`) };
print(2);//printing 2
print()// error
print(null)//printing null
@bobdobbalina
bobdobbalina / array-unique.js
Last active June 3, 2020 14:36
Javascript: Get Unique Values From An Array
const array = [1, 1, 2, 3, 5, 5, 1]
const uniqueArray = [...new Set(array)];
console.log(uniqueArray); // Result: [1, 2, 3, 5]
// OR
let uniqueArray = [...new Set([1, 2, 3, 3,3,"school","school",'ball',false,false,true,true])];
>>> [1, 2, 3, "school", "ball", false, true]
@bobdobbalina
bobdobbalina / remove-falsy-from-array.js
Last active June 3, 2020 14:33
Javascript: Removing Falsy Values From Arrays
myArray.filter(Boolean);
// OR, IF YOU WANT TO MAKE MODIFICATIONS ON THE FLY
myArray
.map(item => {
// Do your changes and return the new item
})
.filter(Boolean);
@bobdobbalina
bobdobbalina / merge-objects.js
Last active June 3, 2020 14:33
Javascript: Merge several objects together
const user = {
name: 'John Ludwig',
gender: 'Male'
};
const college = {
primary: 'Mani Primary School',
secondary: 'Lass Secondary School'
};
@bobdobbalina
bobdobbalina / sort-number-arrays.js
Last active June 3, 2020 14:34
Javascript: Sort number arrays
[0, 10, 4, 9, 123, 54, 1].sort((a, b) => a - b);
>>> [0, 1, 4, 9, 10, 54, 123]
@bobdobbalina
bobdobbalina / promises-complete.js
Last active June 3, 2020 14:34
Javascript: Wait until promises ar complete
const PromiseArray = [
Promise.resolve(100),
Promise.reject(null),
Promise.resolve("Data release"),
Promise.reject(new Error('Something went wrong'))];
Promise.all(PromiseArray)
.then(data => console.log('all resolved! here are the resolve values:', data))
.catch(err => console.log('got rejected! reason:', err))
@bobdobbalina
bobdobbalina / remove-items-from-array.js
Last active August 2, 2021 15:34
Javascript: Remove items from array
// If you know multiple values
const items = ['a', 'b', 'c', 'd', 'e', 'f'];
const valuesToRemove = [ 'c', 'd' ];
const filteredItems = items.filter(( item ) => !valuesToRemove.includes( item ));
// ["a", "b", "e", "f"]