Skip to content

Instantly share code, notes, and snippets.

View MiguelSavignano's full-sized avatar

Miguel Savignano MiguelSavignano

View GitHub Profile
jest.mock('axios');
axios.create.mockReturnThis();
axios.get.mockResolvedValueOnce(Promise.resolve({
data: myMockData
}));
@MiguelSavignano
MiguelSavignano / swagger-spec
Last active July 21, 2021 23:35
Resolve $ref in openapi definitions.
#! /usr/bin/env node
const parser = require('swagger-parser');
const PATH = process.argv[2]
parser.dereference(PATH).then((document => {
console.log(JSON.stringify(document, null, 2))
}))
// ./swagger-spec ./example/petstore.json > petstore-spec.json
@MiguelSavignano
MiguelSavignano / readYamlFiles.js
Created May 28, 2021 02:17
Read folders with multiple yaml files and parse in a single object-
// project
// --path
// ----config.yml
// --path2
// ----config.yml
// { project: { path: { config: object }, path2: { config: object } } }
const globby = require('globby');
const fs = require('fs');
@MiguelSavignano
MiguelSavignano / TestPage.jsx
Created March 5, 2021 15:11
React - Nested Form
import React, { useState } from 'react';
import { Alert, Button, Col, Form, Modal } from 'react-bootstrap';
import 'bootstrap/dist/css/bootstrap.min.css';
const TestPage = () => {
const defaultIngredient = { name: '', amount: '' };
const [ingredients, setIngredients] = useState([defaultIngredient]);
function addIngredient() {
setIngredients([...ingredients, defaultIngredient]);
}
@MiguelSavignano
MiguelSavignano / get_routes.rb
Created June 17, 2020 22:00
Routes to CSV, rails runner get_routes.rb
class CSVFormatter
def initialize
@buffer = []
end
def result
@buffer.join("\n")
end
def section_title(title)
@MiguelSavignano
MiguelSavignano / package.json
Last active February 14, 2020 11:33
Webpack for build html, css, js. themes
{
"name": "build-themes",
"version": "1.0.0",
"description": "build html themes in a single file",
"main": "webpack.config.js",
"directories": {
"lib": "lib"
},
"scripts": {
"build": "npx webpack --config webpack.config.js",
@MiguelSavignano
MiguelSavignano / App.d.ts
Created November 20, 2019 11:49
Declaration types for react class
import React from 'react';
import './App.css';
import 'react-table/react-table.css';
import 'react-bootstrap-table/dist/react-bootstrap-table-all.min.css';
declare class App extends React.Component<{}, {
data: any;
loading: boolean;
}> {
constructor(props: any);
componentDidMount(): void;
@MiguelSavignano
MiguelSavignano / DefaultValue.js
Created May 6, 2019 13:47
Decorate class property with ensure default value, boolean can't be null.
const DefaultValue = defaultValue =>
function(target, key) {
let _val = this[key];
// delete old property
if (delete this[key]) {
Object.defineProperty(target, key, {
get: function() {
return !!_val ? _val : defaultValue;
},
@MiguelSavignano
MiguelSavignano / HttpAuth.ts
Created March 26, 2019 20:57
axios http auth client with refresh token
import axios, { AxiosInstance, AxiosRequestConfig } from "axios";
import createAuthRefreshInterceptor from "axios-auth-refresh";
import config from "../config";
export const generateAuthHeader = authToken =>
`Token api_key=${config.API_KEY}, auth_token=${authToken}`;
interface Storage {
get: (key: string) => Promise<string>;
set: (key: string, data: string) => Promise<string>;
@MiguelSavignano
MiguelSavignano / aviableDates.ts
Last active February 19, 2019 22:54
Calculate work days. filter holidates and weekend.
const Holidays = require('date-holidays');
import * as moment from 'moment';
const holidays = new Holidays(process.env.LOCALE || 'ES');
// https://developer.mozilla.org/es/docs/Web/JavaScript/Referencia/Objetos_globales/Date/getDay
const weekendDays = [6, 0];
const isWeekEnd = (date: Date) => weekendDays.indexOf(date.getDay()) !== -1;
const filterAviableDates = (dates: Array<Date>) => {