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 / ed_notes.md
Created February 7, 2024 05:34 — forked from corenting/ed_notes.md
Elite: Dangerous APIs findings
@leodutra
leodutra / obsidian-linux.md
Last active February 27, 2024 16:57
Obsidian free sync using Google Drive on Ubuntu

Mount rclone sync

This config allows us to mount obsidian folder locally, preventing issues with Google Drive hashes

# create obsidian folder on Google Drive, then
# install rclone
curl https://rclone.org/install.sh | sudo bash
# create a "gdrive" remote config
rclone config
@leodutra
leodutra / rust-ubuntu-dev-env-2023.md
Last active January 15, 2024 16:54
Rust + Ubuntu Dev Env 2023 + utillities / tools / cli / plugins / cargo / components / sub commands

Install steps

# update the system
sudo apt update && sudo apt upgrade -y

# install minimal dev stuff
sudo apt install -y \
	build-essential \
	ca-certificates \
@leodutra
leodutra / alacritty.yml
Created June 12, 2023 08:41 — forked from craig-jennings/alacritty.yml
Alacritty/NuShell/Starship Settings
# Configuration for Alacritty, the GPU enhanced terminal emulator.
# Any items in the `env` entry below will be added as
# environment variables. Some entries may override variables
# set by alacritty itself.
#env:
# TERM variable
#
# This value is used to set the `$TERM` environment variable for
# each instance of Alacritty. If it is not present, alacritty will
@leodutra
leodutra / isMobile.js
Last active May 5, 2023 17:57
Detect if browser is mobile - JavaScript - using feature detection
const hasCoarsePointer = () => window.matchMedia("(pointer: coarse)").matches
const hasMobileWidth = (maxWidth = 639) =>
window.matchMedia(`(max-width: ${maxWidth}px)`).matches
const hasMultipleTouchPoints = () => navigator.maxTouchPoints > 1
const hasTouchEvents = () => "ontouchstart" in document.documentElement
export const isMobile = ({ maxWidth } = {}) => {
return (
hasCoarsePointer() &&
hasMultipleTouchPoints() &&
@leodutra
leodutra / getElementsByText.js
Last active November 11, 2022 15:45
Get DOM elements by text content
const getElementsByText = (text, parent) => {
if (!text) return []
const xpath = `//*[text()='${text}']`
const xpathResult = document.evaluate(
xpath,
parent || document,
null,
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
null
)
@leodutra
leodutra / useForceUpdate.ts
Last active January 11, 2023 22:53
Use force update state (React)
import { useCallback, useState } from "react"
export default function useForceUpdate(): VoidFunction {
const [, setValue] = useState<number>(performance.now())
return useCallback((): void => {
setValue(performance.now())
}, [])
}
@leodutra
leodutra / useDistance.ts
Last active April 7, 2022 08:17
useDistance - Hook to simplify distance measurement (Geo)
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 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)