Skip to content

Instantly share code, notes, and snippets.

View jportella93's full-sized avatar
🌶️

Jon Portella jportella93

🌶️
View GitHub Profile
hello gist
git branch | egrep -v 'master|feat/something-neat' | xargs git branch -D
@jportella93
jportella93 / OneLineScroller.jsx
Created September 25, 2020 21:57
The magic wrapper to avoid CSS overflow.
const outerWrapperStyle = {
overflow: 'hidden' // Avoid breaking UI
}
const innerWrapperStyle = {
whiteSpace: 'nowrap', // Render text in one line
display: 'block',
overflow: 'auto', // Scroll overflow if needed
}
@jportella93
jportella93 / collapseGithubSvgDiff.js
Created March 10, 2020 17:05
Collapses all expanded diffs of .svg files in a github PR.
Array.from(document.querySelectorAll(".file-info"))
.filter(node => node.textContent.includes('.svg'))
.forEach(el => {
const btn = el.querySelector('.js-details-target');
if (btn.getAttribute('aria-expanded') === "true") btn.click();
})
@jportella93
jportella93 / capitalize.js
Created January 3, 2020 10:38
Uppercase first letter of a string in JavaScript
function capitalize(s) {
if (typeof s !== 'string') return '';
return s.charAt(0).toUpperCase() + s.slice(1)
}
@jportella93
jportella93 / script.js
Created May 31, 2019 08:16
Conditionally add property to an object JavaScript ES6
const a = {
...(someCondition && {b: 5})
}
@jportella93
jportella93 / cssVariables.js
Last active May 30, 2019 12:04
Set CSS variables and access them with JavaScript.
const stringVariable = getComputedStyle(document.documentElement)
.getPropertyValue('--height'); // '60px'
const heightInPx = Number(stringVariable.match(/[0-9]*/)[0]); // 60
@jportella93
jportella93 / testPerformance.js
Last active April 11, 2019 09:08
Calculating performance of an action on a browser console.
function testPerformance(fn, iterations) {
console.time()
for (let i = 0; i < iterations; i++) {
fn()
};
console.timeEnd()
}
@jportella93
jportella93 / range.js
Created January 31, 2019 19:47
Create a range between to numbers in array form, with optional steps.
const range = (b, e = (b + (b = 0)), s = 1) =>
Array.from({ length: (e - b) / s + 1 }, (v, i) => i * s + b);
// range(beggining, end, step)
// range(10) === [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
// range(-5, 5) === [-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5]
// range(-10, 10, 5) === [-10, -5, 0, 5, 10]
// range(10, 5) === []
// range(10, 5, -1) === [10, 9, 8, 7, 6, 5]
@jportella93
jportella93 / sleep.js
Created December 28, 2018 15:21
Pause execution of script.
// E.G. await sleep(1000)
function sleep(ms) {
if (ms < 0) ms = 0
return new Promise(resolve => setTimeout(resolve, ms));
}