Skip to content

Instantly share code, notes, and snippets.

View danielvanc's full-sized avatar

Daniel Van Cuylenburg danielvanc

View GitHub Profile
@danielvanc
danielvanc / viewport.ts
Last active March 8, 2022 15:01
Find out how far down browser viewport
const scrolledDown = window.scrollY + window.innerHeight;
@danielvanc
danielvanc / line-through-text
Created March 4, 2022 10:50
Line through text styling
h1 {
display: grid;
grid-template-columns: 1fr auto 1fr;
gap: 1em;
}
h1::before,
h1::after {
content: "";
border-top: 0.1em double black;
align-self: center;
@danielvanc
danielvanc / unique-names.ts
Created March 1, 2022 13:46
Unique names with reduce()
const namesOfPeople = [
"Dan",
"Hannah",
"Cameron",
"Nash",
"Dan",
"Hannah",
"Cameron",
"Nash",
"Dan",
@danielvanc
danielvanc / flatten-arrays.ts
Created March 1, 2022 13:45
Flatten arrays with reduce()
var groupedData = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
[10, 11, 12],
];
var flattedData = groupedData.reduce((prev, curr) => {
return prev.concat(curr);
});
@danielvanc
danielvanc / meanvalue.ts
Created March 1, 2022 13:44
Create mean value with reduce()
const newData = [1, 4, 5, 6, 7, 8, 9, 10];
const meanValue = newData.reduce((prev, curr, index, array) => {
const intermediate = prev + curr;
if (index === array.length - 1) {
return intermediate / array.length;
}
return intermediate;
}, 0);
@danielvanc
danielvanc / tailwind-class-overrides
Last active February 28, 2022 14:19
Create initial variant for tailwind css overrides
plugin(function ({ addVariant }) {
addVariant("initial", "html :where(&)");
}),
@danielvanc
danielvanc / gist:24ede485aaf7982d985713a3a1073a9a
Created October 12, 2021 14:23
Typescript: Create type from array of values
const localesList = ["fr", "da", "de", "es", "it", "nl", "en"] as const
type Translations = {
fr: string;
da: string;
de: string;
es: string;
it: string;
nl: string;
en: string;
@danielvanc
danielvanc / callAll.js
Created July 12, 2021 17:15
Calls all functions along with their arguments
function callAll(...fns) {
return (...args) => {
fns.forEach(fn => {
fn && fn(...args)
})
}
}
const numbers = [1, 2, 2, 4, 8, 9, 10 , 12, 14, 18 , 10, 4, 1];
const sortedollection = [... new Set(numbers)];
console.log(sortedollection)
const testArray = 100;
console.log([...Array(testArray).keys()])