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 / HttpStatusCode.ts
Created September 27, 2024 05:27 — forked from scokmen/HttpStatusCode.ts
Typescript Http Status Codes Enum
"use strict";
/**
* Hypertext Transfer Protocol (HTTP) response status codes.
* @see {@link https://en.wikipedia.org/wiki/List_of_HTTP_status_codes}
*/
enum HttpStatusCode {
/**
* The server has received the request headers and the client should proceed to send the request body
@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 July 17, 2024 16:26
Obsidian free sync using Google Drive on Ubuntu + Android

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
@leodutra
leodutra / rust-ubuntu-dev-env-2023.md
Last active June 12, 2024 00:22
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
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>()