Skip to content

Instantly share code, notes, and snippets.

View acabreragnz's full-sized avatar

Toni Cabrera acabreragnz

  • Bixlabs
  • Montevideo, Uruguay
View GitHub Profile
@acabreragnz
acabreragnz / mock-pinia-with-vitest.ts
Last active October 11, 2024 11:06
Mock a pinia store using vitest
import { beforeEach, describe, it, expect } from 'vitest';
import { fn } from '@vitest/spy';
import { useSomeStore } from '@/useSomeStore';
import { createTestingPinia } from '@pinia/testing';
import { setActivePinia } from 'pinia';
describe('useCreditStore - Test with Mocked Getter', () => {
let mockCreditStore: Record<string, any>;
beforeEach(() => {

Visit Counter for the Article Abstract Page

Objective

Implement a visit counter in a Vue2 application using Vuex and Vuetify on the page src/pages/Article/ArticleAbstractPage.vue. This setup includes error handling, a conditional reset mechanism, and a switch for controlling increment functionality, integrated with a managed loading state.

Requirements

  1. Vuex State Management:
#!/bin/bash
# This script, named generate-pr-report.sh, generates a Markdown report of pull requests for specified GitHub users and date ranges within a GitHub project.
# It must be executed within the root directory of the project you want to analyze.
#
# Usage:
# ./generate-pr-report.sh "user1,user2" "2024-02,2024-03"
# This command generates a report for pull requests created by user1 and user2 between February 2024 and March 2024.
#
# ./generate-pr-report.sh "user1"
@acabreragnz
acabreragnz / FeatureFlagProvider.php
Last active August 3, 2024 17:30
Acapedia - Laravel using the FeatureFlagProvider
<?php
// JsonResource
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
use Business\FeatureFlagProvider\FeatureFlagProvider;
use Business\FeatureFlagProvider\FeatureFlags;
@acabreragnz
acabreragnz / FeatureFlagVuexStore.js
Created June 21, 2023 22:02
Acapedia - Vuex store using the featureFlagProvider
import { createStore } from 'vuex';
import axios from 'axios';
import { featureFlagProvider } from '@/lib/featureFlag';
export default createStore({
state: {
products: [],
},
mutations: {
SET_PRODUCTS(state, products) {
@acabreragnz
acabreragnz / FeatureFlagComponent.vue
Last active August 3, 2024 17:30
Acapedia - Vue component using the featureFlagsMixin
<template>
<div>
<div :class="{'new-feature': isFeatureActive, 'old-feature': !isFeatureActive}">
<!-- Content goes here when MILESTONE_NEW_FEATURE_ENABLED is enabled/disabled -->
<button @click="fetchData">Fetch Data</button>
<div v-if="apiData">{{ apiData }}</div>
</div>
<p>{{ computedMessage }}</p>
</div>
@acabreragnz
acabreragnz / compraPesosMediaBrou.js
Last active June 9, 2023 01:15
Este script te permite convertir una cantidad de dólares a pesos UY, utilizando el valor del dólar actual a la media, obtenido de la pagina de ebrou cotizaciones. https://www.brou.com.uy/cotizaciones
(function () {
const selectorToFloat = (selector) => parseFloat(document.querySelector(selector).textContent.trim().replace(',', '.'));
const floatToLocaleString = (number) => number.toLocaleString('es-UY', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
const dolares = prompt('¿Cuántos dólares desea comprar?');
const compra = selectorToFloat('table > tbody > tr:nth-child(2) > td:nth-child(3)');
const venta = selectorToFloat('table > tbody > tr:nth-child(2) > td:nth-child(5)');
const media = parseFloat(((compra + venta) / 2).toFixed(2));
const pesos = parseFloat((dolares * media).toFixed(2));
document.addEventListener('DOMContentLoaded', function() {
console.log('loading zendesk form builder');
let REPORT_BUG_ARTICLE_ID = '6509556532759';
let REPORT_BUG_TICKET_ID = '6504444995991';
let CONTACT_US_ARTICLE_ID = '6510266315671';
let CONTACT_US_TICKET_ID = '5754824917015';
let FORM_PARENT_ID = 'request-form';
@acabreragnz
acabreragnz / auth.ts
Created March 18, 2020 00:55
Authentication in Nestjs using JWT and Local strategires
# src/api/auth/passport/jwt.strategy.ts
import { ExtractJwt, Strategy } from 'passport-jwt';
import { PassportStrategy } from '@nestjs/passport';
import { Injectable } from '@nestjs/common';
import { ConfigService } from 'src/api/config/config.service';
import { UsersProvider } from 'src/api/users/users.provider';
import { JwtService } from '@nestjs/jwt';
@Injectable()
@acabreragnz
acabreragnz / embed-code.js
Created July 16, 2019 20:49
Simple example about creating embed code
// index.html
// embed code
<script type="text/javascript" id="hs-script-loader" async defer src="//online-script.com/script-loader/XXXX.js"></script>
// online-script.com/script-loader/XXXX.js
(function (id, src) {
if (document.getElementById(id)) { return; }
var js = document.createElement('script');
js.src = src;
js.type = 'text/javascript';