Skip to content

Instantly share code, notes, and snippets.

View leo-bianchi's full-sized avatar

Leo Bianchi leo-bianchi

  • Alpar Service
  • São Paulo, SP
View GitHub Profile
@leo-bianchi
leo-bianchi / consolelog.js
Created November 28, 2019 20:04
Js file with good practices tips.
// DEBUG
// Printing objects on console
const foo = {name: 'tom', age: 30};
const bar = {name: 'harry', age: 50};
const baz = {name: 'john', age: 19};
console.log({ foo, bar, baz }) // To show objects names on console.
// Styling with css
console.logo('%c My friends', 'color: orange; font-weight: bold');
// Console table
@leo-bianchi
leo-bianchi / verifyMultiRowDuplicates.js
Created November 28, 2019 20:16
Servicenow catalog item onChange client script to verify duplicates inside multi-row variable set
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '' || newValue == 'false') {
return;
}
var multiRowSysId = 'sys_id';
var checkBoxField = 'os_horarios_forao_totalmente_preenchidos';
// Mensagem de erro
@leo-bianchi
leo-bianchi / original.js
Last active December 7, 2019 22:24
Refatorando condições
console.time('test');
const saldosQtd = [
{
qtd: 1
},
{
qtd: 10
}
];
@leo-bianchi
leo-bianchi / simple-array-sum.js
Created April 5, 2020 01:36
Simple Array Sum (HackerRank)
// Without Reduce
function simpleArraySum(ar) {
let total = 0;
for(let elem in ar) {
total += ar[elem]
}
return total;
}
// With Reduce
function stockAndCount(n, arr) {
let pairs = 0; // pairs number
const colors = arr.reduce((acc, val) => {
acc[val] ? (acc[val] += 1) : (acc[val] = 1);
return acc;
}, {}); // return an object with colors (numbers) as keys and quantity as value
Object.keys(colors).forEach((n) => { // for each key in colors
let _pair = parseInt(colors[n] / 2); // looks for even numbers
if (_pair >= 1) pairs += _pair; // total
@leo-bianchi
leo-bianchi / diagonal-difference.js
Last active April 5, 2020 05:14
Diagonal Difference (HackerRank)
// Without reduce
function diagonalDifference(arr) {
let sum = 0;
for (let i = 0; i <= arr.length - 1; i++) {
sum += arr[i][i] - arr[i].reverse()[i];
}
return Math.abs(sum);
}
// With reduce
@leo-bianchi
leo-bianchi / agenda.py
Created October 27, 2020 18:02
I don't wanna cry alone right now
lista = []
agenda = {}
def listAll():
print('----- AGENDA -----')
for i in lista:
for chave, valor in i.items():
print(chave.title(), valor)
print('----- FIM -----')