Skip to content

Instantly share code, notes, and snippets.

View kibolho's full-sized avatar
🚀
Working

Abílio Azevedo kibolho

🚀
Working
View GitHub Profile
// timer.start('PROCESS');
// YOUR PROCESS TO MEASURE
// timer.end();
import log from './log';
const logTimer = () => {
let _initiTime: number;
let _title = '';
@kibolho
kibolho / storage.ts
Last active March 4, 2021 18:24
useLocalStorage
import AsyncStorage from '@react-native-community/async-storage';
class Storage {
async set(
key: string,
value: string | Date | Record<string, unknown>,
): Promise<any> {
return await AsyncStorage.setItem(key, JSON.stringify(value));
}
@kibolho
kibolho / cacheHandler.ts
Last active July 1, 2021 11:46
Cache Handler
// TO USE:
// Add a interceptor to the request:
// api.interceptors.request.use((request) => cacheHandler.requestHandler(request));
// api.interceptors.response.use(
// (response) => cacheHandler.responseHandler(response),
// (error) => cacheHandler.errorHandler(error),
// );
import { AxiosRequestConfig, AxiosResponse } from 'axios';
import Storage from './Storage';
function generatePDF(ssID, sheetId, fileName) {
// Base URL
const url = 'https://docs.google.com/spreadsheets/d/SS_ID/export?'.replace('SS_ID', ssID);
var rangeParam = '&r1=0' + '&r2=82' + '&c1=0' + '&c2=11'
const exportOptions =
'exportFormat=pdf&format=pdf' + // export as pdf / csv / xls / xlsx
'&size=A4' + // paper size legal / letter / A4
'&portrait=true' + // orientation, false for landscape
@kibolho
kibolho / InterceptorAxiosRefreshToken.js
Last active October 26, 2022 14:41
Interceptor Axios Refresh Token
Interceptor Axios RefreshToken
let isRefreshing = false;
let failedRequestsQueue: any[] = [];
api.interceptors.response.use(
(response) => {
return response;
},
async (error: AxiosError) => {
@kibolho
kibolho / index.ts
Last active November 22, 2022 17:43
Stringify Objects and Arrays into Query Params
import stringify from './stringfy';
const params = [{"teste": "1"},{"teste": "2"},{"teste": "3"}];
const stringParams = stringify(params, {
encodeValuesOnly: true,
encode: false,
encoder: encodeURIComponent,
addQueryPrefix: true,
});
@kibolho
kibolho / removeDependencyFromYarnLock.js
Created December 6, 2022 00:04
Remove dependency from yarn lock
// add to package.json
// "postinstall": "node scripts/removeDependencyFromYarnLock.js"
const fs = require('fs');
const FILE_SRC = 'yarn.lock';
const REPLACE = '';
const replace = (path, opts = 'utf8') =>
new Promise((resolve, reject) => {
@kibolho
kibolho / regexSubdomain
Last active March 9, 2023 21:10
Regex to get subdomain
const url = "painel.toloja.com.br";
const regex = url.match(/[a-z]+\.?(([a-z]+)\.(([a-z]+)\.[a-z]+\.[a-z]+))[:\d]*/);
const mainUrl = regex ? (regex[2]=== "dev" ? regex[1]: regex[3]) : "defaultOrganizationUrl";
const newOrganization = regex ? regex[4] : "defaultOrganization";
console.log(regex);
console.log(mainUrl);
console.log(newOrganization);
@kibolho
kibolho / stringfy.ts
Last active March 9, 2023 22:07
Stringfy
/* eslint-disable no-bitwise */
interface StringifyOptions {
encoder?: any;
encode?: boolean;
encodeValuesOnly?: boolean;
addQueryPrefix?: boolean;
allowDots?: boolean;
charset?: string;
charsetSentinel?: boolean;
@kibolho
kibolho / actionDeployToS3.yml
Created March 16, 2023 16:51
Action to deploy to S3
name: Deploy to S3 (Prod)
on: workflow_dispatch
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix: