Skip to content

Instantly share code, notes, and snippets.

View FeMaffezzolli's full-sized avatar

Felipe Maffezzolli FeMaffezzolli

View GitHub Profile
@FeMaffezzolli
FeMaffezzolli / searchDepthValue.js
Last active June 16, 2020 10:16
Search value in object by concatened string of keys of nested objects.
/**
* Search value in object by concatened string of keys of nested objects.
*
* @example
*
* Find street name from object:
*
* const obj = {
* address: {
* district: {
@FeMaffezzolli
FeMaffezzolli / stringFromSeconds.ts
Created July 3, 2020 22:40
stringFromSeconds.ts
/**
* @example
*
* Get "00:20" from 20 or "01:16" from 76
*
*/
function stringFromSeconds(seconds: number): string {
const date = new Date(0)
date.setSeconds(seconds)
const [sliceFrom, offset] = seconds >= 3600
@FeMaffezzolli
FeMaffezzolli / formatCurrencyValue.ts
Created July 16, 2020 20:20
Format currency value
const formatValue = (value: number): string =>
Intl.NumberFormat('pt-BR', {
style: 'currency',
currency: 'BRL',
}).format(value);
@FeMaffezzolli
FeMaffezzolli / horizontal-scroll.css
Created July 24, 2020 19:31
Pure CSS Horizontal Scroll
.wrapper {
display: flex;
flex-wrap: nowrap;
overflow-x: auto;
}
.wrapped {
flex: 0 0 auto;
}
@FeMaffezzolli
FeMaffezzolli / patternVector.ts
Created August 13, 2020 00:57
Pattern Vector
const patternVector = [0.5276690030033288, 1.0149928060892972, 1.9035450216269536, 2.192746911523759, 0.44680492166066216]
@FeMaffezzolli
FeMaffezzolli / timeoutStateChangers.ts
Last active August 18, 2020 00:08
State Changer Based on Sequential Timeouts
/**
* In this example shows an implementation of handling the change of audio volume
* based on sequentials timeout functions.
*
*/
let volume = 0
function setVolume(volume: number) { console.log(volume) }
@FeMaffezzolli
FeMaffezzolli / easing.js
Created August 18, 2020 00:24 — forked from gre/easing.js
Simple Easing Functions in Javascript - see https://github.com/gre/bezier-easing
/*
* Easing Functions - inspired from http://gizma.com/easing/
* only considering the t value for the range [0, 1] => [0, 1]
*/
EasingFunctions = {
// no easing, no acceleration
linear: t => t,
// accelerating from zero velocity
easeInQuad: t => t*t,
// decelerating to zero velocity
@FeMaffezzolli
FeMaffezzolli / shuffleArray.ts
Last active September 12, 2020 14:36 — forked from snowman-repos/gist:3820849
JavaScript: Shuffle Array
/**
* Respect immutability folks.
*/
const toBeSortedNewArray = [...originalArray]
toBeSortedNewArray.sort(() => return 0.5 - Math.random());
@FeMaffezzolli
FeMaffezzolli / isValidDate.ts
Last active September 4, 2020 19:54
Is valid date format dd-mm-yyyy
/**
* Receives a date in the following format
*/
function isValidDate(date: string) {
return /^(?:(?:31(\/|-|\.)(?:0?[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0?[13-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)0?2\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0?[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$/g.test(date)
}
@FeMaffezzolli
FeMaffezzolli / mediaFormatConverter.sh
Last active September 29, 2020 21:50
Media format converter (using ffmpeg)
# Both below work fine.
ffmpeg -i input.mp3 -vbr 4 -vn output.m4a
ffmpeg -i input.wav -vbr 4 -vn output.m4a