Skip to content

Instantly share code, notes, and snippets.

View GiovanniRiefolo's full-sized avatar
🎯
Focusing

Giovanni Riefolo GiovanniRiefolo

🎯
Focusing
View GitHub Profile
@GiovanniRiefolo
GiovanniRiefolo / index.js
Last active June 30, 2023 21:26
Return an array of unique values and add a value using new Set
View index.js
// Data array
const data = [{key: 'value 1'}, {key: 'value 1'}, {key: 'value 2'}, {key: 'value 3'}]
// Extended version
// 1. get all values
// 2. create a new Set and get unique values
// 3. create a new array and add a new value
const values = data.map(value => value.key) // ['value 1', 'value 1', 'value 2', 'value 3']
const uniqueValues = new Set(values) // {'value 1', 'value 2', 'value 3'}
const newUniqueValues = [...uniqueValues, 'value 4'] // ['value 1', 'value 2', 'value 3', 'value 4']
// Short Version (all-in-one)
@GiovanniRiefolo
GiovanniRiefolo / index.html
Last active May 17, 2023 13:32
Responsive image full markup
View index.html
<!DOCTYPE html>
<html>
<head>
<title>Responsive image full markup example</title>
<!--
Don't preload if <picture> is used
@https://web.dev/preload-responsive-images/#preload-and-lesspicturegreater
-->
<link rel="preload" href="image_landscape.jpg" imgsrcset="image_landscape.jpg 1x, image_landscape@2x.jpg 2x" as="image">
</head>
@GiovanniRiefolo
GiovanniRiefolo / index.js
Created February 8, 2023 22:56
Usage of .toLocaleDateString for Date object format base on locale options
View index.js
// Get today date value
const today = new Date()
console.log(today) // Wed Feb 08 2023 23:26:49 GMT+0100 (Ora standard dell’Europa centrale)
// Italian date format
const localeIT = "it-IT"
const optionsIT = { weekday:"long", year: "numeric", month: "long", day: "numeric" }
// English / GB date format
const localeGB = "en-GB"
@GiovanniRiefolo
GiovanniRiefolo / index.html
Created February 7, 2023 00:19
Skip links
View index.html
<html>
<head>
<title>Skip links</title>
</head>
<style>
.skip-link{
position: absolute;
z-index: 99;
left: -50%;
right: -50%