Skip to content

Instantly share code, notes, and snippets.

View fmartins-andre's full-sized avatar

André Martins fmartins-andre

View GitHub Profile
@fmartins-andre
fmartins-andre / git-remove-local-branches.sh
Last active July 22, 2024 13:35
Remove local branches that were merged
#!/bin/bash
echo 'Removing origins...'
git remote prune origin
BRANCHES=`git branch -vv | grep 'origin/.*: gone]' | awk '{print $1}'`
if [[ `wc -l "$BRANCHES" 2>/dev/null` -gt 0 ]]; then
echo 'Removing branches:'
echo $BRANCHES
@fmartins-andre
fmartins-andre / toggle-dark-mode.sh
Created July 18, 2024 00:49
Toggle between Gnome light and dark modes
#!/bin/bash
lightMode="'prefer-light'"
darkMode="'prefer-dark'"
ligthTheme="'Adwaita'"
darkTheme="'Adwaita-dark'"
function toggleMode {
@fmartins-andre
fmartins-andre / create-unique-refs-elements-map.md
Created August 20, 2023 23:09
How to create unique refs for elements being rendered via array.map()

You could define a ref, and then inside the object, make multiple subvalues based on the key of the child:

const ref = useRef({})

{array.map((item)=><div key={item.id} ref={ref.current[item.id] ??= { current: null }}>{item.id}</div>)}

Example: https://playcode.io/1096173

Another approach is callback refs:

@fmartins-andre
fmartins-andre / how-to-differ-objects-in-js.md
Created July 26, 2023 14:59
How to differ objects in JavaScript

To check what the real type of and variable, run this command:

  Object.prototype.toString.call(myVar)

It'll return something like [object Object]. The second word is the real type of the variable.

Some examples:

@fmartins-andre
fmartins-andre / useDebouncedFn.ts
Created October 24, 2022 16:25
Debounce a React.js function
import { DebouncedFunc } from "lodash"
import debounce from "lodash.debounce"
import { useMemo } from "react"
export default function useDebouncedFn<T extends (...args: any[]) => void>(fn: T, wait?: number) {
return useMemo(() =>(
debounce((...args:any[]) => {fn(...args)}, wait ?? 300) as DebouncedFunc<T>
), [fn, wait])
}
@fmartins-andre
fmartins-andre / wayland-chrome-screensharing.md
Created May 11, 2022 11:31
chrome shows a black screen on screen sharing on wayland

How to enable wayland screen sharing on chrome browsers

Firefox (84+) supports this method by default, while on Chromium (73+) one needs to enable WebRTC PipeWire support by setting the corresponding (experimental) flag at the URL chrome://flags/#enable-webrtc-pipewire-capturer.

This requires xdg-desktop-portal and one of its backends to be installed. The available backends are:

  • xdg-desktop-portal-gnome for GNOME.
  • xdg-desktop-portal-kde for KDE.
  • xdg-desktop-portal-wlr for wlroots-based Wayland compositors (e.g. Sway, dwl)
@fmartins-andre
fmartins-andre / .gitconfig
Last active June 6, 2024 20:51
Git global config file
[user]
signingkey = CASDF9879ASDF
name = Me
email = myemail@gmail.com
[gpg]
program = gpg
[core]
editor = vim
[diff]
tool = meld
@fmartins-andre
fmartins-andre / toggleMic.sh
Last active January 9, 2022 16:58
Toggle microfone capture ON/OFF using command line. Useful with keyboard shortcut.
### reference: https://askubuntu.com/a/576507
on=/usr/share/icons/Adwaita/48x48/status/microphone-sensitivity-high-symbolic.symbolic.png
off=/usr/share/icons/Adwaita/48x48/status/microphone-disabled-symbolic.symbolic.png
amixer set Capture toggle \
&& amixer get Capture | grep '\[off\]' \
&& notify-send "Mic switched OFF" "Mic capture was disabled!" --icon=$off \
|| notify-send "Mic switched ON" "Mic capture was enabled!" --icon=$on
@fmartins-andre
fmartins-andre / import-openvpn-networkmanager.md
Created December 13, 2021 11:53
Import an openvpn file to Gnome NetworkManager

Import OpenVPN file to NetworkManager

tags: linux, gnome, networkManager, pkcs12, p12

reference: askubuntu

This article intends to be reference when importing a openvpn file to NetworkManager on linux

  • Save the files in a folder;
  • Import the .ovpn file with the following command:
@fmartins-andre
fmartins-andre / manjaro-font-ligatures-vscode-usersettings.md
Last active August 31, 2023 18:05
Add ZSH font ligatures to VSCode on Manjaro

Add font ligatures to the code editor:

  1. install ttf-firacode-nerd font:
    sudo pacman -S ttf-firacode-nerd
  2. configure it in vscode. add the following line to the user settings.json file:
    "editor.fontFamily": "Fira Code"