Skip to content

Instantly share code, notes, and snippets.

View brunojppb's full-sized avatar
🌱
code gardening...

Bruno Paulino brunojppb

🌱
code gardening...
View GitHub Profile

Clear old local branches

This helps to git your local git clean by deleting all branches, but develop, main and master:

git branch -l | egrep -v "(^\*|master|main|develop)" | xargs git branch -D
@brunojppb
brunojppb / icon_padding.sh
Created February 13, 2024 10:57
Add padding to your MacBook navbar icons
defaults -currentHost write -globalDomain NSStatusItemSelectionPadding -int 6
defaults -currentHost write -globalDomain NSStatusItemSpacing -int 6
@brunojppb
brunojppb / tf-format.sh
Created December 22, 2023 10:45
Format Terraform files on a pre-coomit hook
#!/bin/sh
# Apply Terraform formatting to any .tf files modified during
# git changes that are staged.
# Make sure that you have terraform <YOUR_TERRAFORM_VERSION> installed.
# You can use TFSwitch to manage different versions of Terraform at once
# See: https://tfswitch.warrensbox.com/Install/
REQUIRED_TF_VERSION="Terraform v0.12.31"
# Halt the script if any pipe operations fail
@brunojppb
brunojppb / speed_up_ffmpeg.md
Created December 18, 2023 22:40
Speed up Video with ffmpeg

To speed up a video using FFMPEG via the cli:

ffmpeg -i my_video.mp4 -vf "setpts=(PTS-STARTPTS)/3" -crf 18 new_video.mp4

Where 3 is the 3x speed.

@brunojppb
brunojppb / routeMatcher.ts
Last active December 5, 2023 13:39
How to match Remix routes with route patterns so we can track using tracing libraries like Datadog
import { matchPath } from '@remix-run/react'
import fs from 'node:fs'
import * as path from 'node:path'
/**
* Given a request path, tries to find a Remix route path pattern
* that matches with an existing route in your Remix app.
*
* Make sure to generate the Remix routes file during your build with:
*

Debugging NodeJS projects via VS Code

create a launch config under .vscode with the following:

// .vscode/launch.json
{
  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
 // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
@brunojppb
brunojppb / direct_deps_count.js
Last active August 23, 2022 10:49
Count how many direct dependencies a monorepo has.
const { readdir } = require('fs/promises');
const { join } = require('path');
const fs = require('fs');
const { set } = require('date-fns');
const readdirRecursive = async dir => {
const files = await readdir(dir, { withFileTypes: true });
const paths = files.map(async file => {
const path = join(dir, file.name);
@brunojppb
brunojppb / docker-redis-run.md
Last active August 4, 2022 11:24
Run redis with Docker one-liner

Run redis with Docker in a one-liner

Bind the default Redis port (6379) to the host port (6379). Now you can access Redis from your host machine via localhost:6379.

docker run --name my-redis -p 6379:6379 --rm redis
@brunojppb
brunojppb / esm-package.md
Created February 2, 2022 16:43 — forked from sindresorhus/esm-package.md
Pure ESM package

Pure ESM package

The package linked to from here is now pure ESM. It cannot be require()'d from CommonJS.

This means you have the following choices:

  1. Use ESM yourself. (preferred)
    Use import foo from 'foo' instead of const foo = require('foo') to import the package. You also need to put "type": "module" in your package.json and more. Follow the below guide.
  2. If the package is used in an async context, you could use await import(…) from CommonJS instead of require(…).
  3. Stay on the existing version of the package until you can move to ESM.
@brunojppb
brunojppb / Slack_upload.sh
Created January 30, 2021 10:10
Upload a file to Slack via console. Useful for one-off CI pipelines
#!/usr/bin/env bash
# This bash script makes use of the Slack API to upload files.
# I found this useful due to the fact that the attachement option
# available in incoming webhooks seems to have an upper limit of
# content size, which is way too small.
#
# See also: https://api.slack.com/methods/files.upload
# safety first