Skip to content

Instantly share code, notes, and snippets.

View LeandrodeLimaC's full-sized avatar
🎯
Focusing

Leandro de Lima LeandrodeLimaC

🎯
Focusing
View GitHub Profile

Keybase proof

I hereby claim:

  • I am leandrodelimac on github.
  • I am leandrodelimac (https://keybase.io/leandrodelimac) on keybase.
  • I have a public key ASDLQC_VNwlvdwlL4NKU6ZBS8iGxo3axWl-HNRk-gFa63Qo

To claim this, I am signing this object:

@LeandrodeLimaC
LeandrodeLimaC / random-date.js
Created December 21, 2020 16:00 — forked from miguelmota/randomDate.js
Random date in JavaScript
function randomDate(start, end) {
return new Date(start.getTime() + Math.random() * (end.getTime() - start.getTime()));
}
console.log(randomDate(new Date(2012, 0, 1), new Date()));
@LeandrodeLimaC
LeandrodeLimaC / sortList.js
Last active December 30, 2020 00:13
Sort list by parameters, you can specify a default field, the actual field to be filtered and a order for comparation
export const sortList = ( list, field_default, field = field_default, order = 'a_z' ) => {
list.sort(comparator(field, order));
};
const comparator = (field, order) => {
return (a, b) => {
const comparation_table = {
a_z: a[field] == b[field] ? 0 : a[field] < b[field] ? -1 : 1,
z_a: a[field] == b[field] ? 0 : a[field] > b[field] ? -1 : 1,
};
@LeandrodeLimaC
LeandrodeLimaC / wrapperFactory.js
Last active December 26, 2022 19:44
Wrapper factory that receives if it's a ShallowMount or not. It's helpful to easy your (and mine) life when creating vue unit tests (You can extend this to import and use Router, Vuex, etc)
import Vue from 'vue';
import Vuetify from 'vuetify';
import { createLocalVue, shallowMount, mount } from '@vue/test-utils';
// I'do prefer to create a mocks file for those global fellas
// import mocks from './mocks';
Vue.use(Vuetify);
@LeandrodeLimaC
LeandrodeLimaC / async-hook.js
Last active January 5, 2021 20:07
asyncHook will receive a promise and execute it returning reactive properties that will keep track of the state of your promise, you can easily store this state return in some variable to use somewhere your code
/*
* Returns a "state" reactive object, that contains the following properties
* result: Result from promise if there's any
* error: Error from promise if there's any
* isLoading: Boolean that signals if our promise is Loading or not
* retry_attempts: Tracks how many retries we already did
*
* And the following method
* retry: Will automatically retry our promise and reasign all values
*/
@LeandrodeLimaC
LeandrodeLimaC / toast.js
Last active January 28, 2021 05:23
Insert dynamic component in a vue instance (as Plugin)
import snackBarComponent from '@/components/global/snackBar';
const snackBarPlugin = {
install: (Vue, options = {}) => {
let isHolderCreated = false;
const idName = 'snackbar',
ToastConstructor = Vue.extend(snackBarComponent);
const createHolder = () => {
let holder = document.createElement('div')
@LeandrodeLimaC
LeandrodeLimaC / guiderMixin.vue
Last active March 11, 2021 15:02
Driver js on VUE 2 ( "driver.js": "^0.9.8" )
<script>
import Driver from 'driver.js';
import 'driver.js/dist/driver.min.css';
import { steps } from './steps';
export default {
computed: {
driver() {
return new Driver({
interface Observer {
update: () => void;
}
interface Subject {
subscribe: (observer: Observer) => void,
unsubscribe: (observer: Observer) => void,
notify: () => void,
}
// Constructors
// Be careful when using
// Constructor pattern
function C() {
this.instanceMember = 'Whoops!!'
}
const c = C() // Forgot 'new'
@LeandrodeLimaC
LeandrodeLimaC / click-outside.js
Last active March 9, 2024 02:36
Vue directive click outside element
// @ts-nocheck
import Vue from 'vue'
const events = ['click', 'touchstart', 'scroll']
function onClickOutside ({ event, el, handler }) {
const isClickOutside = event.target !== el && !el.contains(event.target)
if (!isClickOutside) { return null }