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 / load-hours.js
Created November 22, 2016 15:22
All the hours in a day in 12-hour clock format with a defined inverval
/**
* All the hours in a day in 12-hour clock format with a defined inverval
*
* @example
* // returns [
* '12:00 AM',
* '12:15 AM',
* '12:30 AM',
* '12:45 AM',
* '01:00 AM',
@acabreragnz
acabreragnz / select_distance_knex.js
Last active September 30, 2020 16:37
This module extends the knex query builder with selectDistance method, the method adds a virtual column to the current query (qb) with the alias as, in which resides the calculated distance from the geoPoint to the entity.location column. It also accepts some options parameters like the unit (km | mi) and the decimalPrecision of the result. Deps…
var knex;
/**
* This module extends the knex query builder with selectDistance method,
* The method adds a virtual column to the current query (qb) with the alias as, in which
* resides the calculated distance from the geoPoint to the entity.location column.
* It also accepts some options parameters like the unit (km | mi) and the decimalPrecision of the result.
* Deps: Postgis
* @example
@acabreragnz
acabreragnz / rps.ex
Last active October 25, 2017 01:33
Rock Scissors Paper game in Elixir! (remember to wrap this inside a module)
@weapons ~w(rock scissors paper)a
def rps(user_choice) when is_binary(user_choice), do: is_valid_choice(String.to_atom(user_choice))
def rps(user_choice) when is_atom(user_choice), do: is_valid_choice(user_choice)
def rps(user_choice), do: {:lost, "Invalid type!"}
defp is_valid_choice(user_choice) when user_choice in @weapons, do: time_to_play(user_choice)
defp is_valid_choice(user_choice), do: {:lost, "Invalid choice!"}
defp time_to_play(user_choice) do
@acabreragnz
acabreragnz / crypto_system.ex
Last active November 10, 2017 16:35
Caesar Cipher, using a different key for each different word (key_seed for word in first place, key_seed + 1 for word in second_place, ...). Also we have a force brute function to find the possible keys
defmodule CryptoSystem do
def encrypt(text, key_seed) do
words = String.split(text, " ");
words
|> Enum.with_index()
|> Enum.map(&encrypt_word(&1, key_seed))
|> Enum.join(" ")
end
@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';
@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()
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 / 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));
@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 / 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) {