Skip to content

Instantly share code, notes, and snippets.

View brunos3d's full-sized avatar
:shipit:
hunting bytes 🏹

Bruno Silva brunos3d

:shipit:
hunting bytes 🏹
View GitHub Profile
@brunos3d
brunos3d / readme.md
Last active September 15, 2023 14:35
Create React Global Context to share between packages and apps.

This example shows abstracts the way Apollo Client creates its Context components to avoid context duplication, you can see the Apollo original code here

The main idea is to give you the ability to share a React Context between packages and applications, like Microfrontends with Module Federation.

// global-context.ts

import * as React from "react";

export function getGlobalContext<P = {}>(
@brunos3d
brunos3d / readme.md
Last active September 15, 2023 13:54
Sentry Hubs on Microfrontends with Module Federation

Remote that shares the components defines a Sentry.hub instance defining some tags that will be used by the host during the dispatch of the logs to Sentry server

import * as Sentry from "@sentry/browser";

const hub = new Sentry.Hub();

hub.configureScope((scope) => {
  scope.setTag("Host", "shop");
 scope.setTag("Team", "shop-team");
@brunos3d
brunos3d / next.config.js
Last active April 2, 2025 19:15
How to copy/use node_modules assets in Next.js public folder with copy-webpack-plugin
const path = require('path');
const CopyPlugin = require('copy-webpack-plugin');
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
/**
*
* @param {import('webpack').Configuration} config
* @returns {import('webpack').Configuration}
@brunos3d
brunos3d / webpack.config.js
Last active July 4, 2023 05:20
Webpack load env-file using Dotenv Plugin using Nx pattern (webpack.config.js)
const { composePlugins, withNx } = require('@nx/webpack');
const Dotenv = require('dotenv-webpack');
const fs = require('fs');
const path = require('path');
// check for available env file using Nx conventions and return the path
function resolveEnvFile(basePath = __dirname) {
const envFiles = [
`.env.${process.env.NX_TASK_TARGET_CONFIGURATION}.${process.env.NX_TASK_TARGET_TARGET}`,
@brunos3d
brunos3d / wait-for-task.ts
Created July 2, 2023 22:55
Wait for Meilisearch Task
import MeiliSearch from 'meilisearch';
export type WaitForTaskOptions = {
client: MeiliSearch;
taskUid: number;
retries?: number;
retryDelay?: number;
customErrorMessage?: string;
};
const hrefMonkeyPatch = () => {
const originalCreateElement = React.createElement;
React.createElement = function createElement () {
const args = Array.prototype.slice.call(arguments);
if (!args[1]) {
args[1] = {};
}
@brunos3d
brunos3d / readme-light-dark-image.md
Last active May 2, 2023 18:38
Dynamic Images for your Readme files based on GitHub theme

Your Alt Description

Images based on GitHub Theme

@brunos3d
brunos3d / copy-all-envs.sh
Created January 19, 2023 20:50
A shell script that make a backup for your env files keeping the same directory structure
#!/bin/bash
input_path=$1
output_path=$2
# Find all .env files in the input path
for file in $(find "$input_path" -name "*.env"); do
# Get the file path relative to the input path
relative_path="${file#$input_path/}"
useEffect(() => {
// componentDidMount
}, [])
useEffect(() => {
// componentDidUpdate
}, [something, anotherThing])
useEffect(() => {
return () => {
@brunos3d
brunos3d / falsy-filter(Boolean)-trick.js
Created December 13, 2022 14:38
How to quickly filter out falsy values from an array
arrayWithFalsyItems.filter(Boolean)