Skip to content

Instantly share code, notes, and snippets.

View leodutra's full-sized avatar
🦙
Llama and other LLMs

Leo Dutra leodutra

🦙
Llama and other LLMs
View GitHub Profile
@leodutra
leodutra / useIntersection.ts
Last active May 7, 2022 04:28
useIntersection - Hook to simplify usage of Intersection Observer
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 November 7, 2021 09:46
Performance patterns & Self-Healing Techniques

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 / headset-setup-bt.sh
Last active October 22, 2024 09:17
Bluetooth headset/ headphone Ubuntu 20.04 - tested with Sony WH-1000XM4 - shell script
#!/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 July 24, 2021 21:02
Create array doing mapping sample
Array.from({ length: 130 }, (_, i) => (i + 2) * 5000).reverse()
@leodutra
leodutra / formatPrice.js
Last active July 24, 2021 21:03
Format price using Intl.NumberFormat
const formatPrice = ({
price,
fraction = 2,
currency = 'USD',
currencyDisplay = 'symbol', // 'narrowSymbol' is not supported by Safari yet
locale = 'en-US',
signDisplay = 'auto',
...props
}) => {
if (isNaN(Number(price))) {
@leodutra
leodutra / - npm license values
Last active May 16, 2021 02:49 — forked from kemitchell/-
npm license values
74925 NONE
54706 MIT
9268 ISC
3050 BSD
1521 BSD-2-CLAUSE
791 APACHE-2.0
699 APACHE 2.0
392 BSD-3-CLAUSE
364 WTFPL
346 UNKNOWN
@leodutra
leodutra / repo-rinse.sh
Created May 7, 2021 06:41 — forked from nicktoumpelis/repo-rinse.sh
Cleans and resets a git repo and its submodules
git clean -xfd
git submodule foreach --recursive git clean -xfd
git reset --hard
git submodule foreach --recursive git reset --hard
git submodule update --init --recursive
@leodutra
leodutra / settings.json
Last active September 19, 2023 18:15
VSCode - Visual Studio Code settings
{
"editor.tabSize": 4,
"[javascript]": {
"editor.tabSize": 2,
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[javascriptreact]": {
"editor.tabSize": 2,
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
@leodutra
leodutra / replaceStrByRender.ts
Last active August 11, 2021 04:11
React - replace string by render or component
const replaceStrByRender = (
str: string,
substr: string | RegExp,
render: (part: string, i: number) => JSX.Element
) => {
if (!str || !substr) return str
const parts = str.split(substr)
const results: Array<string | JSX.Element | null> = []
let index = 0
for (let i = 0; i < parts.length; i++) {
@leodutra
leodutra / .gitlfstracks
Created December 25, 2020 22:01 — forked from bdombro/.gitlfstracks
Git LFS Default Tracks - Common binary file extensions
"To include this, run `cat .gitlfstrack | xargs git lfs track`"
"*.3ds"
"*.3g2"
"*.3gp"
"*.7z"
"*.a"
"*.aac"
"*.adp"
"*.ai"
"*.aif"