Last active
September 24, 2025 19:23
-
Star
(365)
You must be signed in to star a gist -
Fork
(40)
You must be signed in to fork a gist
-
-
Save mikowl/5fa1a06c06264afaa544bb6b8af641b1 to your computer and use it in GitHub Desktop.
Revisions
-
mikowl revised this gist
Apr 29, 2023 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -90,14 +90,13 @@ const getSelectedText = () => window.getSelection().toString(); // Simple star rating ex: rating(5) will print ★★★★★ const rating = star => "★".repeat(Math.max(0, Math.min(star, 5))).padEnd(5,"☆" ); // because this primeagen tweet: // https://twitter.com/ThePrimeagen/status/1646204396655591439 // Check if is an array const isArr = (arr) => Array.isArray(arr); // Left pad function const leftPad = (s, l, c = ' ') => c.repeat(l - s.length) + s; // Check if num is positive const isPosi = (num) => num > 0; -
mikowl revised this gist
Apr 13, 2023 . 1 changed file with 11 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -91,3 +91,14 @@ const getSelectedText = () => window.getSelection().toString(); const rating = star => "★".repeat(Math.max(0, Math.min(star, 5))).padEnd(5,"☆" ); // because this primeagen tweet: // https://twitter.com/ThePrimeagen/status/1646204396655591439 // Check if is an array const isArr = (arr) => Array.isArray(arr); // Left pad function const lefPad = (s, l, c = ' ') => c.repeat(l - s.length) + s; // Check if num is positive const isPosi = (num) => num > 0;
-
mikowl revised this gist
Apr 4, 2023 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -36,7 +36,7 @@ const add42 = n => (console.log(n), n + 42); console.log({ a, b, c, d, e}); // Random hex color const generateRandomHexColor = () => `#${Math.floor(Math.random() * 0xffffff).toString(16).padEnd(6, "0")}`; // We love Javascript that's why instead of Math.floor we use // Note: Use with caution, it won't work for big (>32bit) or negative numbers -
mikowl revised this gist
Jan 18, 2023 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -87,3 +87,7 @@ const navigateBack = () => history.back(); // Get selected text const getSelectedText = () => window.getSelection().toString(); // Simple star rating ex: rating(5) will print ★★★★★ const rating = star => "★".repeat(Math.max(0, Math.min(star, 5))).padEnd(5,"☆" ); -
mikowl revised this gist
Oct 2, 2022 . 1 changed file with 1 addition and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -36,9 +36,7 @@ const add42 = n => (console.log(n), n + 42); console.log({ a, b, c, d, e}); // Random hex color const generateRandomHexColor = () => `#${Math.floor(Math.random() * 0xffffff).toString(16).padEnd(6, "0"}`; // We love Javascript that's why instead of Math.floor we use // Note: Use with caution, it won't work for big (>32bit) or negative numbers -
mikowl revised this gist
Aug 19, 2022 . 1 changed file with 9 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -62,11 +62,15 @@ console.log(getUnique(arr)); const isDarkMode = () => window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches; console.log(isDarkMode()); // Scroll to top of page const scrollToTop = () => window.scrollTo({ top: 0, behavior: 'smooth' }); // Scroll to bottom of page const scrollToBottom = () => window.scrollTo({ top: document.body.scrollHeight, behavior: 'smooth' }); // Scroll to top of an element const scrollToEl = (element) => element.scrollIntoView({ behavior: "smooth", block: "start" }); // Scroll to elements bottom const scrollToElb = (element) => element.scrollIntoView({ behavior: "smooth", block: "end" }); // Check if an element is focused const elem = document.querySelector(' .text-input'); -
mikowl revised this gist
Jun 17, 2022 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -79,5 +79,9 @@ const arrIsEmpty = !(Array.isArray(arr) && arr.length > 0); // Redirect user const redirect = url => location.href = url // ex: recdirect("https://google.com") // Go back to previous page const navigateBack = () => history.back(); // Get selected text const getSelectedText = () => window.getSelection().toString(); -
mikowl revised this gist
May 11, 2022 . 1 changed file with 15 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -66,4 +66,18 @@ console.log(isDarkMode()); const scrollToTop = (element) => element.scrollIntoView({ behavior: "smooth", block: "start" }); // Scroll To Bottom const scrollToBottom = (element) => element.scrollIntoView({ behavior: "smooth", block: "end" }); // Check if an element is focused const elem = document.querySelector(' .text-input'); const isFocus = elem == document.activeElemnt; // Check if an array is empty let arr = [1,2,3,4]; const arrIsEmpty = !(Array.isArray(arr) && arr.length > 0); // Redirect user const redirect = url => location.href = url // ex: recdirect("https://google.com") -
mikowl revised this gist
Mar 11, 2022 . 1 changed file with 27 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,4 @@ // Inspired by https://twitter.com/coderitual/status/1112297299307384833 and https://tapajyoti-bose.medium.com/7-killer-one-liners-in-javascript-33db6798f5bf // Remove any duplicates from an array of primitives. const unique = [...new Set(arr)] @@ -38,7 +37,33 @@ console.log({ a, b, c, d, e}); // Random hex color '#'+(~~(Math.random()*0xffffff)).toString(16).padEnd(6,0) // or const generateRandomHexColor = () => `#${Math.floor(Math.random() * 0xffffff).toString(16)}`; // We love Javascript that's why instead of Math.floor we use // Note: Use with caution, it won't work for big (>32bit) or negative numbers ~~anyNumber // Shuffle Array const shuffleArray = (arr) => arr.sort(() => Math.random() - 0.5); const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; console.log(shuffleArray(arr)); // Copy to Clipboard const copyToClipboard = (text) => navigator.clipboard?.writeText && navigator.clipboard.writeText(text); copyToClipboard("Hello World!"); // Unique Elements const getUnique = (arr) => [...new Set(arr)]; const arr = [1, 1, 2, 3, 3, 4, 4, 4, 5, 5]; console.log(getUnique(arr)); // Detect Dark Mode const isDarkMode = () => window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches; console.log(isDarkMode()); // Scroll to Top const scrollToTop = (element) => element.scrollIntoView({ behavior: "smooth", block: "start" }); // Scroll To Bottom const scrollToBottom = (element) => element.scrollIntoView({ behavior: "smooth", block: "end" }); -
mikowl revised this gist
Mar 17, 2020 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,6 +6,8 @@ const unique = [...new Set(arr)] // Sleep in async functions. Use: await sleep(2000). const sleep = (ms) => (new Promise(resolve => setTimeout(resolve, ms))); // or const sleep = util.promisify(setTimeout); // Type this in your code to break chrome debugger in that line. debugger; -
mikowl revised this gist
Apr 2, 2019 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -38,4 +38,5 @@ console.log({ a, b, c, d, e}); '#'+(~~(Math.random()*0xffffff)).toString(16).padEnd(6,0) // We love Javascript that's why instead of Math.floor we use // Note: Use with caution, it won't work for big (>32bit) or negative numbers ~~anyNumber -
mikowl revised this gist
Apr 2, 2019 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -29,13 +29,13 @@ items[n % items.length] const addFortyTwo = number => console.log(number) || number + 42 // Same as above const add42 = n => (console.log(n), n + 42); // Log variables with names. I love this trick with object ❤️ console.log({ a, b, c, d, e}); // Random hex color '#'+(~~(Math.random()*0xffffff)).toString(16).padEnd(6,0) // We love Javascript that's why instead of Math.floor we use ~~anyNumber -
mikowl renamed this gist
Apr 1, 2019 . 1 changed file with 2 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,5 @@ // By @coderitual // https://twitter.com/coderitual/status/1112297299307384833 // Remove any duplicates from an array of primitives. const unique = [...new Set(arr)] -
mikowl created this gist
Apr 1, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,42 @@ By @coderitual https://twitter.com/coderitual/status/1112297299307384833 -- // Remove any duplicates from an array of primitives. const unique = [...new Set(arr)] // Sleep in async functions. Use: await sleep(2000). const sleep = (ms) => (new Promise(resolve => setTimeout(resolve, ms))); // Type this in your code to break chrome debugger in that line. debugger; // Just plain english. [...].every(Number.isFinite); // Returns all non-falsy values from an array. [...].filter(Boolean) // Array destructuring to see matching elements. let [r, g, b, a] = [255, 0, 0, 255]; // Object destructuring to reduce multiple lines of code to a single line. let {width, height} = resolution; // Gets an item from the list and wraps around to the start if n is larger than the list. items[n % items.length] // Console.log in array function without adding curly braces. const addFortyTwo = number => console.log(number) || number + 42 // Same as above const add42 = n => (console.log(n), number + 42); // Log variables with names. I love this trick with object ❤️ console.log({ a, b, c, d, e}); // Random hex color '#'+Math.floor(Math.random()*16777215).toString(16) // We love Javascript that's why instead of Math.floor we use ~~anyNumber