Skip to content

Instantly share code, notes, and snippets.

View tiagobnobrega's full-sized avatar
🏠
Working from home

Tiago Nobrega tiagobnobrega

🏠
Working from home
View GitHub Profile
@tiagobnobrega
tiagobnobrega / open_iterm_window.scpt
Created September 24, 2024 16:17
open iterm apple script
set appName to "iTerm"
if application appName is running then
tell application "iTerm" to create window with default profile
else
tell application "iTerm" to activate
end if
@tiagobnobrega
tiagobnobrega / attachSubcomponent.ts
Created February 7, 2024 10:49
React Typescript Subcomponents
import React from 'react';
/**
* Attaches subcomponents to a parent component for use in
* composed components. Example:
*
* <Parent>
* <Parent.Title>abc</Parent.Title>
* <Parent.Body prop1="foobar"/>
* </Parent>
@tiagobnobrega
tiagobnobrega / docket_to_colima_mac_os.md
Created January 23, 2024 20:28
From docker to colima on iOS
@tiagobnobrega
tiagobnobrega / async-retry.ts
Created December 3, 2021 12:16
Retry async function
type JitterStrategy = "static" | "incremental" | "random";
export interface AsyncRetryOptions {
maxAttempts?: number;
jitterInterval?: number; //time in ms
jitterIncrement?: number; // percent or time in ms
jitterStrategy?: JitterStrategy;
}
function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
@tiagobnobrega
tiagobnobrega / rabbitManager.js
Created November 12, 2021 22:11
Rabbit MQ consumer with Retry
const amqp = require('amqp-connection-manager');
/**
* * Creates an instance of a rabbitMQ manager
* @param rabbitUrl - rabbit URL connection
* @param systemName - Optional prefix used for shared topology elements (wait queues and retry dispatcher dlx)
* @param onConnect - Optional connection callback
* @param onDisconnect - Optional disconnection callback
* @returns {{sendMessage: (function(*=, *=): Promise<boolean>), consumeWithRetry: ((function(*=, *, *=): Promise<void>)|*)}}
*/
@tiagobnobrega
tiagobnobrega / formatters.ts
Last active January 18, 2024 11:44
javascript common formatters
const normalizePhone = (value: string): string => {
if (!value) return '';
let newNumber = value.replace(/\D/g, '');
newNumber = newNumber.substring(0, 11);
newNumber = newNumber.replace(/^(\d{2})(\d)/g, '$1 $2');
newNumber = newNumber.replace(/(\d)(\d{4})$/, '$1-$2');
return newNumber;
};
const normalizeDocument = (value: string): string => {
@tiagobnobrega
tiagobnobrega / cfg.ts
Created March 26, 2021 17:08
Simple .env transformer helper in typescript
import * as dateFns from 'date-fns';
const ENV = process.env;
interface CfgMetaData {
isRequired:boolean;
requiredKey:string;
}
interface Cfg {
required():RequiredCfg;
@tiagobnobrega
tiagobnobrega / node.eslintrc.js
Created March 22, 2021 13:18
Nodejs eslint config
module.exports = {
plugins: [
"@typescript-eslint",
"eslint-comments",
"jest",
"promise",
"unicorn",
],
extends: [
"plugin:@typescript-eslint/recommended",
@tiagobnobrega
tiagobnobrega / react.eslintrc.js
Created March 15, 2021 16:43
React Typescript eslintrc configuration
module.exports = {
plugins: [
"@typescript-eslint",
"eslint-comments",
"jest",
"promise",
"unicorn",
],
extends: [
"plugin:@typescript-eslint/recommended",
@tiagobnobrega
tiagobnobrega / ID.js
Created July 11, 2018 20:24
ID - a unique ID/name generator for JavaScript
// Generate unique IDs for use as pseudo-private/protected names.
// Similar in concept to
// <http://wiki.ecmascript.org/doku.php?id=strawman:names>.
//
// The goals of this function are twofold:
//
// * Provide a way to generate a string guaranteed to be unique when compared
// to other strings generated by this function.
// * Make the string complex enough that it is highly unlikely to be
// accidentally duplicated by hand (this is key if you're using `ID`