Skip to content

Instantly share code, notes, and snippets.

View zanonnicola's full-sized avatar
💭
I like Kotlin

Nicola Zanon zanonnicola

💭
I like Kotlin
View GitHub Profile
import type { NextApiRequest, NextApiResponse } from 'next';
import nodemailer from 'nodemailer';
import type SMTPTransport from 'nodemailer/lib/smtp-transport';
import Mail from 'nodemailer/lib/mailer';
import { FormDataKey, PayloadFormData } from '../../lib/useRMVform';
import { ManVanInputs } from '../../page-components/MvForm';
import { RMVInputs } from '../../page-components/RmvForm';
import {
buildBaseHTML,
buildCallbackHTML,
@zanonnicola
zanonnicola / k6_script.js
Created November 16, 2020 20:19
K6 Load test example
import { group, sleep, check } from "k6";
import { parseHTML } from 'k6/html';
import { Trend } from "k6/metrics";
import http from "k6/http";
import { randomIntBetween, uuidv4 } from "https://jslib.k6.io/k6-utils/1.0.0/index.js";
const usersToken = JSON.parse(open("./users.json"));
const URL = "https://myapp.com";
const TEST_NAME = "First Test - simple user flow";
@zanonnicola
zanonnicola / validators.ts
Created November 19, 2019 11:21
Credit Card Validation for VueJS
const mustBeValidDateFormat = (value: string): boolean => /^[0-9.\/]+$/i.test(value);
const mustBeValidMonth = (value: string): boolean => {
const [month] = value.split('/');
if (!/^\d*$/.test(month)) { return false; }
const inputMonth = parseInt(month, 10);
return inputMonth > 0 && inputMonth < 13;
};
@zanonnicola
zanonnicola / Modal.js
Last active November 2, 2018 09:34
Simple ES6 Singleton. This is a simple implementation it doesn't shield you from all the things but good enough in majority of the cases. Simple to reason about as well.
const modalHOC = store => {
return class Modal {
constructor(config = {}) {
}
myPublicMethod() {
if(store.getState().isOpen) {
// Do your magic
}
}
}
@zanonnicola
zanonnicola / routerMiddleware.js
Created October 24, 2018 05:30
Handles URL changes
export const routerMiddleware = history => () => next => action => {
switch (action.type) {
case PUSH:
history.push(action.payload);
break;
case REPLACE:
history.replace(action.payload);
break;
case GO:
history.go(action.payload);
@zanonnicola
zanonnicola / index.js
Last active June 6, 2018 11:43
JS Helper functions - Fire function when browser is free
const deBounced = debounce(() => {
// The RAF ensures it doesn't run when tab isn't visible
requestAnimationFrame(() => {
// the RIC makes sure the browser isn't busy with something
// timeout: max amount of time to wait.
requestIdleCallback(fn(), { timeout: 500})
})
}, 30000)
@zanonnicola
zanonnicola / github_gpg_key.md
Created March 26, 2018 11:40 — forked from ankurk91/github_gpg_key.md
Github : Signing commits using GPG (Ubuntu/Mac)

Github : Signing commits using GPG (Ubuntu/Mac) 🔐

  • Do you have an Github account ? If not create one.
  • Install required tools
  • Latest Git Client
  • gpg tools
# Ubuntu
sudo apt-get install gpa seahorse
# Mac
@zanonnicola
zanonnicola / customEvent.js
Last active January 5, 2018 17:30
A simple polyfill for CustomEvent (support back to any IE 9).
(function () {
if ( typeof window.CustomEvent === "function" ) return false;
function CustomEvent ( event, params ) {
params = params || { bubbles: false, cancelable: false, detail: undefined };
var evt = document.createEvent( 'CustomEvent' );
evt.initCustomEvent( event, params.bubbles, params.cancelable, params.detail );
return evt;
}
@zanonnicola
zanonnicola / index.html
Created November 24, 2017 13:16
HTML5 Form validation. Based on https://jsfiddle.net/Loilo/jdct84x6/3/
<form>
<input
type="number"
placeholder="Enter 42"
min="42"
max="42"
required>
<input
type="email"
@zanonnicola
zanonnicola / query.sql
Created November 24, 2017 12:00
This is way faster
/*
create index ORDER_2_PRODUCT_IDX on order_product(`order_id`);
create index ORDER_2_TOTAL_IDX on order_total(`order_id`);
create index ORDER_STATUS_IDX on order(`order_status_id`);
create index ORDER_2_STATUS_IDX on order_status(`order_status_id`);
create index ORDER_OPTION_IDX on order(`order_product_id`);
create index ORDER_2_OPTION_IDX on order_option(`order_product_id`);
*/
select count(`o`.`order_status_id`) from `order` o where o.`order_status_id` = 0;