Elegant code

A collection of beautiful programming solutions

Dec 12, 2020

--

HTML, CSS & JavaScript

Month number to MMM string

Source: Unknown origin

function util_monthMMM(i) {
var monthNames = "JanFebMarAprMayJunJulAugSepOctNovDec";
return monthNames.substr((Math.min(11, Math.max(0, i)) * 3), 3);
}
console.log(util_monthMMM(today.getMonth()));

Month number to MMMM string

Source: Unknown origin

function util_monthMMMM(i) {
var monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
return monthNames[i];
}
console.log(util_monthMMMM(today.getMonth()));

Integer in custom length string format

Source: Unknown origin

function util_intStrLength(i, length) {
return ("00000000000000000000" + i).slice(-length);
}
console.log(util_intStrLength(1,5));

Random integer

Source: https://stackoverflow.com/a/7228322

function util_randomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
}
console.log(util_randomInt(0,100));

Random HEX color

Source: https://css-tricks.com/snippets/javascript/random-hex-color/

function util_randomColorHex() {
return "#" + Math.floor(Math.random()*16777215).toString(16);
}
console.log(util_randomColorHex());

Other resources

https://www.w3schools.com/

https://css-tricks.com/

https://stackoverflow.com/

Microsoft Office

Unprotect a Word Document (Save as XML and remove enforcement)

https://superuser.com/a/937232

Summary

--

--

QM Learning
QM Learning

Written by QM Learning

0 Followers

QM Learning creates tutorials for professional documents and templates. We exist to inspire businesses, employees, students and the quality inclined!

No responses yet