Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
I like Kotlin

Nicola Zanon zanonnicola

💭
I like Kotlin
View GitHub Profile
View gist:72556a21eb648ee3d8825fa37d6bede4
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 Nov 16, 2020
K6 Load test example
View k6_script.js
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 Nov 19, 2019
Credit Card Validation for VueJS
View validators.ts
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 Nov 2, 2018
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.
View Modal.js
const modalHOC = store => {
return class Modal {
constructor(config = {}) {
}
myPublicMethod() {
if(store.getState().isOpen) {
// Do your magic
}
}
}
View routerMiddleware.js
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 Jun 6, 2018
JS Helper functions - Fire function when browser is free
View index.js
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 Mar 26, 2018 — forked from ankurk91/github_gpg_key.md
Github : Signing commits using GPG (Ubuntu/Mac)
View github_gpg_key.md

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 Jan 5, 2018
A simple polyfill for CustomEvent (support back to any IE 9).
View customEvent.js
(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;
}
View index.html
<form>
<input
type="number"
placeholder="Enter 42"
min="42"
max="42"
required>
<input
type="email"
@zanonnicola
zanonnicola / query.sql
Created Nov 24, 2017
This is way faster
View query.sql
/*
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;