Skip to content

Instantly share code, notes, and snippets.

@luislobo14rap
luislobo14rap / youtube-iframe-faster.js
Created August 20, 2020 12:06
youtube-iframe-faster.js
// youtube-iframe-faster.js v1
function youtubeIframeFaster(youtubeID, userOptions = {}, callback) {
if (typeof youtubeID !== 'string'){
return console.error('The youtubeID argument is required and must be of the type string.');
};
let element = document.querySelector(`#${youtubeID}`),
options = { // everyone is boolean
autoplay: false,
autoTitle: true, // iframe attribute title="${videoTitle}"
loop: false,
// milA.js v1
function milA(repeat = 1){
let a = '';
for(let i = 0; i < repeat; i++){
a += 'a';
};
return a;
};
@luislobo14rap
luislobo14rap / cache-expires-after.js
Created August 7, 2020 22:10
cache-expires-after.js
// cache-expires-after.js v1
function cacheExpiresAfter(delay = 1, prefix = '', suffix = '') { // seconds
let now = new Date().getTime().toString();
now = now.substring(now.length - 11, 10); // remove decades and milliseconds
now = parseInt(now / delay).toString();
return prefix + now + suffix;
};
@luislobo14rap
luislobo14rap / change-url-without-reload.js
Last active May 12, 2023 20:13
change-url-without-reload.js
// change-url-without-reload.js v1
function changeURLWithoutReload(newUrl){
let url = getURL();
return window.history.pushState(undefined, undefined, url + '/' + newUrl.replace(/^\//, ''));
};
// getURL.js v1
function getURL(url = window.location.href){
return url.split(/[?#&]/)[0].replace(/\/+$/, '');
};
@luislobo14rap
luislobo14rap / log-css.js
Last active January 12, 2023 06:07
log-css.js
// log-css.js v2
const log = console.log.bind()
const css = (text, options) => {
let cssOptions = ''
for (let prop in options) {
const value = options[prop]
prop = camelCaseToDashCase(prop)
cssOptions += `${prop}: ${value}; `
}
return [`%c${text}`, cssOptions.trim()]
@luislobo14rap
luislobo14rap / chrome-export-extensions-id.js
Created July 15, 2020 20:24
chrome-export-extensions-id.js
/* dependencies: jquery: https://code.jquery.com/jquery-3.4.1.min.js
jquery-shadowRoot.js: https://gist.github.com/luislobo14rap/0eeb4ff1c67ada1805e80d3553c7a1a6 */
$('extensions-manager').shadowRoot().find('#items-list').shadowRoot().find('.items-container').find('extensions-item').each(function(){
console.log( $(this).attr('id') );
});
@luislobo14rap
luislobo14rap / math-utils-beta.js
Last active January 29, 2024 14:26
math-utils.js
"Se A é o total, e tenho B, quantos correspondem a 50?"
"Se 'a' é um valor e 'b' é o total, qual a porcentagem que 'a' representa de 'b'?"
// CANSEI CONTINUAR DEPOIS
// math-utils.js v1
Math.avg = (...numbers) => Math.sum(...numbers) / numbers.length
Math.distance = (a, b) => Math.abs(a - b)
Math.isApproximate = (a, b, tolerance = 0) => Math.abs(a - b) <= tolerance
Math.isBetween = (number, min, max) => number >= min && number <= max
Math.isEven = number => number % 2 === 0
@luislobo14rap
luislobo14rap / remove-of-array.js
Created June 27, 2020 06:26
remove-of-array.js
// remove-of-array.js v1
function removeOfArray(array_, item) {
while (array_.indexOf(item) > -1) {
let i = array_.indexOf(item);
if (i > -1) {
array_.splice(i, 1);
};
};
return array_;
};
@luislobo14rap
luislobo14rap / my.component.html
Created June 26, 2020 02:11
angular-ngFor-using-number
<div *ngFor="let index of repeatFor(3)">
{{index}}
</div>
@luislobo14rap
luislobo14rap / reclame-aqui.js
Created June 24, 2020 01:28
reclame-aqui.js
// reclame-aqui.js v2
// https://www.reclameaqui.com.br
var s = ' ';
var $ = function(selector){
return document.querySelector(selector);
};
var $$ = function(selector){
return document.querySelectorAll(selector);
};
var url = window.location.href;