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

Simple example with a Pure CF Worker

import jwt from "jsonwebtoken"; // Use um bundler para incluir dependΓͺncias externas, se necessΓ‘rio.

addEventListener("fetch", (event) => {
  event.respondWith(handleRequest(event.request));
});

async function handleRequest(request) {
@brunos3d
brunos3d / setup-nvm-with-husky-init.sh
Created March 5, 2025 08:38
How to fix vscode commit gui ".husky/pre-commit: line <number>: npx: command not found" error
mkdir -p ~/.config/husky && echo 'export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm' > ~/.config/husky/init.sh
@brunos3d
brunos3d / readme.md
Last active January 27, 2025 18:33
fucking fix your ollama pull: permission denied error

Just replace PATH_TO_YOUR_MODELS with the absolute (or relative) path to your ollama models directory (usually /usr/share/ollama/.ollama/models/)

sudo find PATH_TO_YOUR_MODELS -type f -exec chown ollama:ollama {} \;
sudo find PATH_TO_YOUR_MODELS -type d -exec chown ollama:ollama {} \;
sudo find PATH_TO_YOUR_MODELS -type f -exec chmod 644 {} \;
sudo find PATH_TO_YOUR_MODELS -type d -exec chmod 755 {} \;

PS: kudos for Jeron_Baffom

@brunos3d
brunos3d / fix_all_repo_permissions.sh
Created December 18, 2024 04:39
This script recursively find git repos from the current folder and revert all files with permission changes
find . -type d -name ".git" -exec sh -c 'repo_dir=$(dirname "{}"); echo "Processando repositΓ³rio: $repo_dir"; cd "$repo_dir" && [ -d .git ] && git diff -p -R --no-ext-diff --no-color --diff-filter=M | grep -E "^(diff|(old|new) mode)" --color=never | git apply' \;
@brunos3d
brunos3d / fix_permissions.sh
Last active December 18, 2024 04:27
A script to securely apply custom file and directory permissions in a user's home directory, ensuring proper access levels for sensitive files, development tools, and shared directories.
#!/bin/bash
#########
##### THIS SCRIPT CAN FUCK YOUR COMPUTER, use it on your own responsibility
#########
# User directory path
read -p "Enter the username or press Enter to use the current user ($(logname)): " input_user
USER_HOME="/home/${input_user:-$(logname)}"
# Function to apply permissions
@brunos3d
brunos3d / .log
Created November 24, 2023 19:55
MF 8 errror after running next dev
bruno in next-mf-host-with-mandatory-libs/apps/remote on ξ‚  main [!?] took 8.3s
➜ npm run dev
> @demo/[email protected] dev
> next dev -p 3011
npm ERR! code ENOWORKSPACES
npm ERR! This command does not support workspaces.
npm ERR! A complete log of this run can be found in: /home/bruno/.npm/_logs/2023-11-24T19_33_46_944Z-debug-0.log
@brunos3d
brunos3d / singleton-by-default-issue-example.jsx
Created October 30, 2023 15:15
An example of a common issue when using singleton: true for all shared packages
// remote
// uses xlib@10 as a singleton
import { generate } from 'xlib'; // hey, I'm a singleton and I will have only one global instance in memory =]
// the federated component
export default function GenerateSomethingButton() {
const content = generate();
return <h1>{content}</h1>;
}
@brunos3d
brunos3d / webpack.config.js
Last active October 24, 2023 22:36
How to proper infer Webpack types to webpack.config.js
const path = require('path');
/**
* @type {import('webpack').Configuration & { devServer?: import('webpack-dev-server').Configuration }}}
*/
module.exports = {
entry: './src/index.js',
output: {
filename: 'main.js',
path: path.resolve(__dirname, 'dist'),
@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");