Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Leo Dutra leodutra

🏠
Working from home
View GitHub Profile
@leodutra
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
leodutra / third-party-cargo.txt
Last active May 10, 2022
3rd-party (third-party) Rust cargo sub commands
View third-party-cargo.txt
Reference: https://github-wiki-see.page/m/rust-lang/cargo/wiki/Third-party-cargo-subcommands
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
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/com.apple.Safari;
rm -Rf ~/Library/Caches/com.apple.WebKit.PluginProcess;
rm -Rf ~/Library/Cookies/*;
rm -Rf ~/Library/Cookies/Cookies.binarycookies;
rm -Rf ~/Library/Preferences/Apple\ -\ Safari\ -\ Safari\ Extensions\ Gallery;
rm -Rf ~/Library/Preferences/com.apple.Safari.LSSharedFileList.plist;
@leodutra
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
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
leodutra / Performance-patterns.md
Last active Nov 7, 2021
Performance patterns & Self-Healing Techniques
View Performance-patterns.md

Performance Patterns

Definitions:

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
leodutra / nw_oodle.bms
Created Oct 16, 2021 — forked from jessy-lua/nw_oodle.bms
New World oodle preset for QuickBMS
View nw_oodle.bms
# ZIP files example 0.4.11
# more info: http://www.pkware.com/documents/casestudies/APPNOTE.TXT
# 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 http://quickbms.aluigi.org
@leodutra
leodutra / ed_notes.md
Created Aug 16, 2021 — forked from corenting/ed_notes.md
Elite: Dangerous APIs findings
View ed_notes.md
@leodutra
leodutra / headset-setup-bt.sh
Last active Aug 2, 2021
Bluetooth headset/ headphone Ubuntu 20.04 - tested with Sony WH-1000XM4 - shell script
View headset-setup-bt.sh
#!/bin/sh
# sudo add-apt-repository ppa:eh5/pulseaudio-a2dp (NOT NEEDED ANYMORE)
sudo apt update
sudo apt install libldac \
libavcodec-extra58 \
pulseaudio \
pulseaudio-module-bluetooth \
blueman
@leodutra
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()