Skip to content

Instantly share code, notes, and snippets.

View DoctorDerek's full-sized avatar
☀️
https://linkedin.com/in/derek-austin Read my blog https://DoctorDerek.medium.com

Dr. Derek Austin DoctorDerek

☀️
https://linkedin.com/in/derek-austin Read my blog https://DoctorDerek.medium.com
View GitHub Profile
@DoctorDerek
DoctorDerek / Example of lodash.clonedeep using require instead of import to deep copy.js
Created April 24, 2022 01:24
Example of lodash.clonedeep using require instead of import to deep copy https://medium.com/p/3242c9eae48
// eslint-disable-next-line @typescript-eslint/no-var-requires
const lodashClonedeep = require("lodash.clonedeep")
const array = [1337, { x: "✅" }, { y: { z: "⚡" } }] // deeply nested array
const copy = lodashClonedeep(array) // shallow copy with lodashClonedeep
console.info(array) // [1337, { x: "✅" }, { y: { z: "⚡" } }]
copy[0] = "leet" // change a primitive value (not nested)
copy[1].x = "❎" // change a deeply nested value
copy[2].y.z = "❌" // change another deeply nested value
console.info(array) // [1337, { x: "✅" }, { y: { z: "⚡" } }]
console.info(copy) // ["leet", { x: "❎" }, { y: { z: "❌" } }]
@DoctorDerek
DoctorDerek / Top 10 Advanced VS Code Settings for Senior Developers 1.json
Created November 1, 2021 05:14
Top 10 Advanced VS Code Settings for Senior Developers by Dr. Derek Austin 🥳 https://medium.com/p/46e348351bd6
"workbench.activityBar.visible": false,
"github.copilot.enable": {
"*": true,
"yaml": false,
"plaintext": false,
"markdown": false,
"env": false
},
@DoctorDerek
DoctorDerek / How to Sort an Object by Key or Property Name in JavaScript.js
Created November 1, 2021 03:17
How to Sort an Object by Key or Property Name in JavaScript by Dr. Derek Austin 🥳 https://medium.com/p/a8c07b179901
const myObj = { Hello: "🌎", Goodnight: "🌛", Hola: "🌮" }
const unsortedMap = new Map(Object.entries(myObj))
console.log(unsortedMap)
// Map(3) {"Hello" => "🌎", "Goodnight" => "🌛", "Hola" => "🌮"}
// Step 1: Turn the Map into an array
const unsortedArray = [...unsortedMap] // same as Array.from
// Step 2: Sort the array with a callback function
const sortedArray = unsortedArray.sort(([key1, value1], [key2, value2]) =>
@DoctorDerek
DoctorDerek / How to Sort an Array of Strings in JavaScript 1.js
Last active November 1, 2021 02:10
How to Sort an Array of Strings in JavaScript by Dr. Derek Austin 🥳 https://medium.com/p/5d59b1ac64be
[1,5,10].sort() // [1, 10, 5]
@DoctorDerek
DoctorDerek / How To Sort a Set in JavaScript ES6.js
Created November 1, 2021 01:26
How To Sort a Set in JavaScript ES6 by Dr. Derek Austin 🥳 https://medium.com/p/51b53f6ef71a
const anArray = [5,3,3,3,4,2,1]
const aSet = new Set(anArray)
console.log(aSet) // Set(5) {5,3,4,2,1}
const uniqueArray = Array.from(aSet)
console.log(uniqueArray) // [5,3,4,2,1]
uniqueArray.sort((a,b)=>a-b)
// .sort((a,b)=>a-b)) to sort numbers
// just .sort() sorts alphabetically
const myObj = { Hello: "🌎", Goodnight: "🌛" }
const myMap = new Map(Object.entries(myObj))
// Add an item
myObj["Hola"] = "🌮"
myMap.set("Hola", "🌮")
// Get an item
console.log(myObj["Hola"]) // 🌮
console.log(myMap.get("Hola")) // 🌮
const myObj = { Hello: "🌎", Goodnight: "🌛", Hola: "🌮" }
const unsortedMap = new Map(Object.entries(myObj))
console.log(unsortedMap)
// Map(3) {"Hello" => "🌎", "Goodnight" => "🌛", "Hola" => "🌮"}
// Step 1: Turn the Map into an array
const unsortedArray = [...unsortedMap] // same as Array.from
// Step 2: Sort the array with a callback function
const sortedArray = unsortedArray.sort(([key1, value1], [key2, value2]) =>
@DoctorDerek
DoctorDerek / meta-tag-for-viewport.html
Created August 24, 2021 03:46
10 Ways to Fix Horizontal Scroll Bars with CSS width: 100vw on Websites https://medium.com/p/39b3a5e81cf
<meta name="viewport"
content="width=device-width, initial-scale=1.0">
@DoctorDerek
DoctorDerek / w-full in Tailwind CSS.html
Created August 24, 2021 03:33
10 Ways to Fix Horizontal Scroll Bars with CSS width: 100vw on Websites https://medium.com/p/39b3a5e81cf
<section class="w-full flex flex-col items-center content-center border-4 border-purple-500 border-solid bg-blue-500">
<div class="text-4xl font-bold bg-gray-100 fixed right-4 bottom-4">Tailwind CSS: w-full</div>
@DoctorDerek
DoctorDerek / How to turn off semicolons in import-sorter.json
Created August 23, 2021 03:24
How to turn off semicolons in import-sorter.json -- How to Sort Imports in TypeScript Automatically in VS Code https://medium.com/p/f4fe4e499bb1
"importSorter.importStringConfiguration.hasSemicolon": false,