Skip to content

Instantly share code, notes, and snippets.

View snsxn's full-sized avatar
💭
I may be slow to respond.

Adrià snsxn

💭
I may be slow to respond.
View GitHub Profile
@snsxn
snsxn / audio-conversion.sh
Last active July 12, 2023 06:56
FFmpeg convert audio file
# WAV to MP3
ffmpeg -i origin.wav -c:a libmp3lame -q:a 7 destination.mp3
# WAV to M4A (96k constant bitrate)
ffmpeg -i origin.wav -c:a libfdk_aac -b:a 96k destination.m4a
# WAV to M4A (variable bitrate)
ffmpeg -i origin.wav -c:a libfdk_aac -vbr 3 destination.m4a
# Add -ac 1 for mixdown to mono
@snsxn
snsxn / search-recursive.js
Created July 10, 2023 14:04
Recursive Array search
const array = [
{ id: 1 },
{ id: 2 },
{ id: 3 },
{ id: 4, children: [
{ id: 6 },
{ id: 7, children: [
{ id: 8 },
{ id: 9 }
]
@snsxn
snsxn / removeDuplicates.js
Created August 26, 2022 14:43
One-line remove duplicates from an Array - JavaScript ES2015, ES6
const removeDuplicates = (arr) => [...new Set(arr)];
@snsxn
snsxn / groupByObjProp.js
Created August 26, 2022 14:42
One-line group an Array by an Object Property - JavaScript ES2015, ES6
const groupBy = (arr, groupFn) => arr.reduce((grouped, obj) => ({...grouped,[groupFn(obj)]: [...(grouped[groupFn(obj)] || []), obj], }), {});
// Using it
const people = [
{ name: 'Matt' },
{ name: 'Sam' },
{ name: 'John' },
{ name: 'Mac' },
];
groupBy(people, (person) => person.name.length);
@snsxn
snsxn / getLargest.js
Created August 26, 2022 14:38
One-line get largest element of an Array - JavaScript ES2015, ES6
const getLargestElement = (arr) => arr.reduce((largest, num) => Math.max(largest, num));
@snsxn
snsxn / getSmallest.js
Created August 26, 2022 14:37
One-line get smallest element of an Array - JavaScript ES2015, ES6
const getSmallestElement = (arr) => arr.reduce((smallest, num) => Math.min(smallest, num));
@snsxn
snsxn / background-video-responsive.css
Last active July 14, 2022 14:18
Full width and height video background CSS
.bg-video {
position: fixed;
z-index: -1;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
@media (min-aspect-ratio: 16/9) {
@snsxn
snsxn / shuffle.js
Last active August 26, 2022 14:35 — forked from guilhermepontes/shuffle.js
3x one-liner Shuffle Array - JavaScript ES2015, ES6
// Original gist
const shuffleArray = arr => arr.sort(() => Math.random() - 0.5);
// Fully random by @BetonMAN
const shuffleArray = arr => arr.map(a => [Math.random(), a]).sort((a, b) => a[0] - b[0]).map(a => a[1]);
// Fisher-Yates shuffle one-liner
const shuffleArray = (arr) => [...Array(arr.length)].map((_, i) => Math.floor(Math.random() * (i + 1))).reduce((shuffled, r, i) => shuffled.map((num, j) => j === i ? shuffled[r] : j === r ? shuffled[i] : num),arr);