Skip to content

Instantly share code, notes, and snippets.

Avatar

Aryan Beezadhur AryanBeezadhur

View GitHub Profile
View is-valid-url.js
function isValidUrl(str) {
var pattern = new RegExp(
'^(https?:\\/\\/)?' + // protocol
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name
'((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path
'(\\?[;&a-z\\d%_.~+=-]*)?' + // query string
'(\\#[-a-z\\d_]*)?$',
'i'
) // fragment locator
@AryanBeezadhur
AryanBeezadhur / full-page-bg-img.css
Created Nov 25, 2021
CSS Full-page background image
View full-page-bg-img.css
html {
background: url(image.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
@AryanBeezadhur
AryanBeezadhur / flex-rows.css
Last active Nov 25, 2021
CSS Flexbox with specified number of boxes in rows
View flex-rows.css
.flex-container {
display: flex;
flex-wrap: wrap;
--flex-gap: 1.25rem;
gap: var(--flex-gap);
}
.flex-child {
--flex-items-per-row: 3;
@AryanBeezadhur
AryanBeezadhur / npm-api-downloads.md
Last active Nov 24, 2021
npm REST API endpoints for package downloads stats
View npm-api-downloads.md
                                      ↓ start date    : ↓ end date (leave blank for stats for one day)
https://api.npmjs.org/downloads/range/{yyyy}-{mm}-{dd}:{yyyy}-{mm}-{dd}/{package}

e.g. get downloads stats for next from 2020/01/01 to 2021/01/01 (1 year):

View comma-thousands-separator.js
function numberWithCommas(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
View fetch-api.js
async function postData(url = '', data = {}) {
// Default options are marked with *
const response = await fetch(url, {
method: 'POST', // *GET, POST, PUT, DELETE, etc.
mode: 'cors', // no-cors, *cors, same-origin
cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
credentials: 'same-origin', // include, *same-origin, omit
headers: {
'Content-Type': 'application/json'
// 'Content-Type': 'application/x-www-form-urlencoded',
@AryanBeezadhur
AryanBeezadhur / center-items-flexbox.css
Created Nov 10, 2021
Center items using CSS flexbox
View center-items-flexbox.css
.flex {
display: flex;
justify-content: center;
align-items: center;
}
@AryanBeezadhur
AryanBeezadhur / link-new-tab.html
Created Nov 10, 2021
HTML Hyperlink that opens in new tab
View link-new-tab.html
@AryanBeezadhur
AryanBeezadhur / link-bottom-border.css
Last active Nov 10, 2021
CSS Bottom-border for links
View link-bottom-border.css
@AryanBeezadhur
AryanBeezadhur / custom-text-selection.css
Last active Nov 10, 2021
CSS Custom text selection appearance
View custom-text-selection.css
::selection {
background: var(--black);
color: var(--white);
}