Skip to content

Instantly share code, notes, and snippets.

View paulmelero's full-sized avatar
Creative developer

Paul Melero paulmelero

Creative developer
View GitHub Profile
@paulmelero
paulmelero / README.md
Last active November 29, 2021 19:02
Simple Debounce Vue 2 Mixin: `simple-debounce-vue-mixin`

SimpleDebounce (Vue Mixin)

If you are listening to changes on an Event (DOM Events) to execute any side effects like performing network requests, you'd probably want to "debounce" your attached function executions.

This is an alternative to lodash.debounce but "vanilla js" packed as a Vue SFC to import it as a mixin.

@paulmelero
paulmelero / index.js
Created September 25, 2019 13:42
`nuxtServerInit` checking if it's mobile
/*
This needs to be in the store/index.js
*/
const mutationTypes = {
SET_MOBILE: 'SET_MOBILE',
}
const checkIfMobileOnServerSide = ({ req, isServer }) => {
if (isServer) return false
@paulmelero
paulmelero / README.md
Last active September 11, 2024 19:28
DeepClone-js: JS utility with circular replacer

DeepClone-js

Utility to clean up circular references while creating a new reference of an object performing a deep copy (as oposite to a shallow copy). Bear in mind it doesn't work with some data types: Date, Map, RegExp, Set, TypedArray...

📦 Install

npm i -S gist:0bce1161cfd2aa91ae7cad9abb42c342
@paulmelero
paulmelero / README.md
Last active November 27, 2020 09:14
`img-exists`
@paulmelero
paulmelero / README.md
Last active July 16, 2020 15:34
Remove unwanted HTML tags from an HTML string (for security reasons)
@paulmelero
paulmelero / line-clamp.scss
Created March 6, 2020 11:06
Truncate lines utility classes scss
// `.truncate-1-line` and `truncate-2-lines`
@each $lines in (1, 2) {
:root .truncate-#{$lines}-line#{if($lines > 1, 's', '')} {
display: -webkit-box;
overflow: hidden;
-webkit-line-clamp: $lines;
-webkit-box-orient: vertical;
}
}
/// <reference types="jest" />
import { mount } from '@vue/test-utils'
import IntersectionComponent from './IntersectionComponent.vue'
const mountComponent = props =>
mount(IntersectionComponent, {
propsData: {
callback: jest.fn().mockImplementation(isVisible => isVisible),
...props
@paulmelero
paulmelero / asyncOnce.js
Created July 22, 2020 15:49
Async once
/**
* Takes a generator function that can yeild async functions.
* When the wrapped generator is called again, the previous call will cancel ASAP.
* Note: it won't cancel in-flight requests made (see: AbortController)
* @param {GeneratorFunction} generator
* @see https://dev.to/chromiumdev/cancellable-async-functions-in-javascript-5gp7
* @author Sam Thorogood
* @returns {(...args: any[]) => Promise<any>}
*/
@paulmelero
paulmelero / main.vue
Created September 30, 2021 12:56
Specificity Challenge
<template>
<p id="one" class="hello">hello world</p>
</template>
<style scoped>
#one {
color: blue;
}
.hello.hello.hello.hello.hello.hello.hello.hello.hello.hello.hello.hello.hello {
@paulmelero
paulmelero / index.js
Last active May 11, 2022 15:26
JS Quiz
const quiz = {
...{ a: { b: 1, c: 3 }},
...{ a: { b: 2 }}
}