Skip to content

Instantly share code, notes, and snippets.

View BrunoGiubilei's full-sized avatar
🏬
Totvs

Bruno Giubilei BrunoGiubilei

🏬
Totvs
View GitHub Profile
@BrunoGiubilei
BrunoGiubilei / script.js
Created April 4, 2022 17:18
JS to embed Webamp JS using the "User Javascript and CSS" chrome extension
This file has been truncated, but you can view the full file.
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else if(typeof exports === 'object')
exports["Webamp"] = factory();
else
root["Webamp"] = factory();
})(window, function() {
@BrunoGiubilei
BrunoGiubilei / script.js
Created March 31, 2022 14:16
Load external script
function carregaJS(u, c) {
var d = document, t = 'script',
o = d.createElement(t),
s = d.getElementsByTagName(t)[0];
o.src = u;
if (c) { o.addEventListener('load', function (e) { c(); }, false)}
s.parentNode.insertBefore(o, s);
}
@BrunoGiubilei
BrunoGiubilei / fetch.js
Last active September 24, 2021 10:35
Fetch em javascript puro
fetch(url)
.then((resp) => resp.json())
.then(function(data) {
console.log(data);
});
// se por acaso o CORS reclama
fetch(url,{
mode: 'no-cors'
})
#!/bin/bash
init() {
killall -q polybar
while pgrep -u $UID -x polybar >/dev/null; do sleep 1; done
polybar sensual
echo "Polybar relançada..."
@BrunoGiubilei
BrunoGiubilei / orderByProp.js
Last active February 18, 2020 16:34
Ordenar array de objetos alfabeticamente
.sort(function(a, b) {
return a.categoria.toString().localeCompare(b.categoria.toString());
})
@BrunoGiubilei
BrunoGiubilei / minMax.js
Created February 17, 2020 17:21
min and max value prototype for array of object
Array.prototype.min = function() {
var self = this, p = arguments[0];
return self
.filter(f => p.zero === false ? f[p.prop] > 0 : f)
.map(m => m[p.prop])
.reduce((a, c) => {
return a = (a === undefined || c < a) ? c : a
});
}
@BrunoGiubilei
BrunoGiubilei / copy.js
Created February 17, 2020 17:20
copy prototype for array of object
Array.prototype.copy = function() {
return this.map(function(e){return {...e}});
}
@BrunoGiubilei
BrunoGiubilei / groupby.js
Created February 14, 2020 16:48
Group By prototype for array of object
Array.prototype.groupBy = function() {
var self = this, p = arguments[0];
return self.map(m => m[p.prop])
.reduce((a, d) => {if (!a.includes(d)) { a.push(d); } return a;}, [])
.map(m => self
.filter(f => f[p.prop] === m));
}
@BrunoGiubilei
BrunoGiubilei / navigate.f7.js
Created December 12, 2019 15:42
navegar para outra page no Framework7
self.$app.view.main.router.navigate('/contatos/clothing/',{animate: false});
@BrunoGiubilei
BrunoGiubilei / filterByAnyPropReturnIndex.js
Created November 22, 2019 11:47
Filtrar dentro de um array de objetos por qualquer propriedade e retornar um array com os indices do array inicial
items.filter(function(reg, i) {
reg.index = i;
return Object.values(reg).find(function(prop) {
return prop !== null && prop.toString().normalize('NFD').replace(/[\u0300-\u036f]/g, "").toUpperCase().indexOf(query.toUpperCase()) >= 0;
}) !== undefined;
}).map(function(reg) {return reg.index});