This file contains 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 characters
const differenceBetweenDates = (date1, date2) => Math.abs(Math.floor((date2 - date1) / (1000 * 60 * 60 * 24))); | |
document.write(differenceBetweenDates("2773-01-17", "2774-01-18")); |
This file contains 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 characters
const objectToURLParams = (obj) => Object.entries(obj).map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`).join('&'); | |
This file contains 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 characters
const secondsToHHMMSS = (seconds) => { | |
const hours = Math.floor(seconds / 3600); | |
const remainingSeconds = seconds % 3600; | |
const minutes = Math.floor(remainingSeconds / 60); | |
const remainingSecs = remainingSeconds % 60; | |
return `${hours}:${minutes}:${remainingSecs}`; | |
}; | |
document.write(secondsToHHMMSS(7320)); |
This file contains 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 characters
const randomizeString = (str) => str.split('').sort(() => 0.5 - Math.random()).join(''); | |
document.write(randomizeString("Every good boy deserves fudge!"); | |
This file contains 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 characters
const checkIsValidIPv4 = (ip) => /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(ip); | |
document.write(checkIsValidIPv4("192.168.1.1")); |
This file contains 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 characters
const checkIsValidUSPhoneNumber = (phone) => /^(?:(?:\+1\s?)?(?:\(?\d{3}\)?[\s.-]?)?\d{3}[\s.-]?\d{4})$/.test(phone); | |
document.write(checkIsValidUSPhoneNumber("+1 (123) 456-7890")); |
This file contains 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 characters
const convertRGBToHSL = (r, g, b) => { | |
[r, g, b] = [r, g, b].map(val => val / 255); | |
const [max, min] = [Math.max(r, g, b), Math.min(r, g, b)]; | |
let h = (max !== min) ? ((max === r ? g - b : (max === g ? b - r : r - g)) / (max - min) + (max === g ? 2 : (max === b ? 4 : 0))) / 6 : 0; | |
let s = (max !== min) ? (l => l > 0.5 ? (max - min) / (2 - max - min) : (max - min) / (max + min))(l) : 0; | |
let l = (max + min) / 2; | |
return { h: Math.round(h * 360), s: Math.round(s * 100), l: Math.round(l * 100) }; | |
}; | |
document.write(convertRGBToHSL(77, 123, 44)); |
This file contains 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 characters
const isMACAddressValid = (mac) => /^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/.test(mac); | |
document.write(isValidMACAddress("AA:22:FF:04:2D")); |
This file contains 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 characters
function get_sum(int $n = 100) { | |
$sum = $n * ($n + 1) / 2; | |
return $sum; | |
} | |
This file contains 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 characters
$pwd = "C:\Users\someusername" | |
$dirinfo = Get-ChildItem($pwd) -recurse | |
$d = $dirinfo.ToString() | |
$stringAsStream = [System.IO.MemoryStream]::new() | |
$writer = [System.IO.StreamWriter]::new($stringAsStream) | |
$writer.write($d) | |
$writer.Flush() | |
$stringAsStream.Position = 0 | |
$output = Get-FileHash -InputStream $stringAsStream | Select-Object Hash | |
$output.hash.ToString() |
NewerOlder