Skip to content

Instantly share code, notes, and snippets.

View valeriocs's full-sized avatar

Valério Correa Sanches valeriocs

  • DB1 Global Software
  • Maringá
View GitHub Profile
@valeriocs
valeriocs / NonAdmin.cmd
Created August 24, 2023 20:02 — forked from ferventcoder/NonAdmin.cmd
Installing Software as a Non-Administrator Using Chocolatey
:: Pick one of these two files (cmd or ps1)
:: Set directory for installation - Chocolatey does not lock
:: down the directory if not the default
SET INSTALLDIR=c:\ProgramData\chocoportable
setx ChocolateyInstall %INSTALLDIR%
:: All install options - offline, proxy, etc at
:: https://chocolatey.org/install
@powershell -NoProfile -ExecutionPolicy Bypass -Command "(iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))) >$null 2>&1" && SET PATH="%PATH%;%INSTALLDIR%\bin"
getUnique(arr, comp) {
const unique = arr
.map(e => e[comp])
// store the keys of the unique objects
.map((e, i, final) => final.indexOf(e) === i && i)
// eliminate the dead keys & store unique objects
.filter(e => arr[e]).map(e => arr[e]);
return unique;
},
@valeriocs
valeriocs / debounce.js
Last active January 22, 2019 19:59
Diretiva para VueJS implementando métodos para ganho de desempenho através de gatilhos como debounce e throttle.
const debounce = (func) => {
let timeout;
const debounced = (...args) => {
const later = () => {
timeout = null;
func(...args);
};
clearTimeout(timeout);
timeout = setTimeout(later, 1000);
if (!timeout) {
@valeriocs
valeriocs / allAreSame.js
Created December 13, 2018 12:52
Returns true if the selected array item value is the same through all array.
allAreSame() {
if (this.array.length) return;
const paramToCompare = this.array[0].key;
const comparation = this.array
.every(({ correspondingKey }) => correspondingKey === paramToCompare);
return comparation;
},
@valeriocs
valeriocs / notAgain.js
Last active December 13, 2018 19:53
Function to remove object from array if receive duplicate.
notAgain(obj) {
const removeHandler = this.array.filter(item => item === obj)
if (removeHandler.length) {
this.array = this.array.filter(item => item !== obj)
return
}
this.array.push(obj)
}
@valeriocs
valeriocs / removeEmpty.js
Created December 3, 2018 18:17
Easy to remove emptys from object
removeEmpty(object) {
const obj = {};
// eslint-disable-next-line no-restricted-syntax
for (const key in object) {
if (
object[key] !== null &&
object[key] !== false &&
object[key] !== undefined
) {
obj[key] = object[key];
@valeriocs
valeriocs / runner.js
Created November 20, 2018 10:15
Webpack 2/3/4 compiling loop fix
const timefix = 11000;
compiler.plugin('watch-run', (watching, callback) => {
watching.startTime += timefix;
callback()
});
compiler.plugin('done', (stats) => {
stats.startTime -= timefix
})
@valeriocs
valeriocs / CypressUpload.js
Last active November 8, 2018 19:20
Cypress Upload custom command.
Cypress.Commands.add('upload_file', (fileName, selector) => {
return cy.get(selector).then(subject => {
return cy.fixture(fileName, 'base64')
.then(Cypress.Blob.base64StringToBlob)
.then(blob => {
const el = subject[0]
const testFile = new File([blob], fileName, { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' })
const dataTransfer = new DataTransfer()
dataTransfer.items.add(testFile)
el.files = dataTransfer.files