Skip to content

Instantly share code, notes, and snippets.

Working from home

Leo Dutra leodutra

Working from home
View GitHub Profile
leodutra / useForceUpdate.ts
Created May 23, 2022
Use force update state (React)
View useForceUpdate.ts
import React, { useState } from 'react'
const useForceUpdate = () => useState()[1]
export default useForceUpdate
leodutra / third-party-cargo.txt
Last active May 10, 2022
3rd-party (third-party) Rust cargo sub commands
View third-party-cargo.txt
cargo-audit - Audit Cargo.lock for crates with security vulnerabilities
cargo-asm, cargo-llvm-ir / cargo show-asm - Shows generates assembly or LLVM IR of Rust code
cargo-benchcmp - Compare output of cargo bench output, both runs over time and same benchmarks in multiple modules (e.g. for comparing multiple implementations)
cargo-bitbake - Generate Yocto's bitbake recipes from your Cargo.toml
cargo-bloat - Find out what takes most of the space in your executable.
cargo-cache - Helps you manage the cargo cache (~/.cargo), print sizes and clear directories
cargo-check - This is a wrapper around cargo rustc -- -Zno-trans. It can be helpful for running a faster compile if you only need correctness checks.
cargo-cook - Cooks your crate (packaging & deploying).
leodutra / clear-safari.bash
Created May 7, 2022
Clear Safari (MacOs) bash
View clear-safari.bash
mv ~/Library/Safari ~/Desktop/Safari-`date +%Y%m%d%H%M%S`;
rm -Rf ~/Library/Cache/*;
rm -Rf ~/Library/Caches/Apple\ -\ Safari\ -\ Safari\ Extensions\ Gallery;
rm -Rf ~/Library/Caches/Metadata/Safari;
rm -Rf ~/Library/Caches/;
rm -Rf ~/Library/Caches/;
rm -Rf ~/Library/Cookies/*;
rm -Rf ~/Library/Cookies/Cookies.binarycookies;
rm -Rf ~/Library/Preferences/Apple\ -\ Safari\ -\ Safari\ Extensions\ Gallery;
rm -Rf ~/Library/Preferences/;
leodutra / useDistance.ts
Last active Apr 7, 2022
useDistance - Hook to simplify distance measurement (Geo)
View useDistance.ts
import { useMemo } from 'react'
type GeoLocation = {
latitude: number
longitude: number
export const useDistance = (pointA?: GeoLocation, pointB?: GeoLocation) =>
useMemo(() => {
const isValid = x => x != null && isFinite(x)
leodutra / useIntersection.ts
Last active May 7, 2022
useIntersection - Hook to simplify usage of Intersection Observer
View useIntersection.ts
import { MutableRefObject, useEffect, useRef, useState } from 'react'
export const useIntersection = (
ref: MutableRefObject<Element | null>,
options?: IntersectionObserverInit | null,
once = false
): boolean => {
const [isIntersecting, setIsIntersecting] = useState(false)
const observerRef = useRef<IntersectionObserver | null>(null)
const optionsRef = useRef<typeof options>()
leodutra /
Last active Nov 7, 2021
Performance patterns & Self-Healing Techniques

Performance Patterns


Express Train

For some tasks, create an alternate path that does only the minimal required work (e.g., for data fetches requiring maximum performance, create multiple DAOs — some enriched, some impoverished)

Hard Sequence

Enforce sequential completion of high-priority tasks, even if multiple threads are available (e.g., chain Ajax calls enabling optional interactions only after minimal page load, even if later calls do not physically depend on earlier returns)

leodutra /
Created Oct 16, 2021 — forked from jessy-lua/
New World oodle preset for QuickBMS
# ZIP files example 0.4.11
# more info:
# note that with some archives like those created by Stuff-it on MacOSX is
# not possible to use this script because they are wrongly built, practically
# they set the comp_size and uncomp_size fields of the "Local file header" at
# 0 and they set them only in the relative "Central directory structure" which
# means that it's necesary to read this one first for extracting the files
# contained in the local header... senseless and stupid
# script for QuickBMS
leodutra /
Created Aug 16, 2021 — forked from corenting/
Elite: Dangerous APIs findings
leodutra /
Last active Aug 2, 2021
Bluetooth headset/ headphone Ubuntu 20.04 - tested with Sony WH-1000XM4 - shell script
# sudo add-apt-repository ppa:eh5/pulseaudio-a2dp (NOT NEEDED ANYMORE)
sudo apt update
sudo apt install libldac \
libavcodec-extra58 \
pulseaudio \
pulseaudio-module-bluetooth \
leodutra / create-mapping-sample.js
Last active Jul 24, 2021
Create array doing mapping sample
View create-mapping-sample.js
Array.from({ length: 130 }, (_, i) => (i + 2) * 5000).reverse()