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 / bitwise-hacks.js
Last active October 30, 2023 02:37
Fast Int Math + Bitwise Hacks For JavaScript
// http://michalbe.blogspot.com.br/2013/03/javascript-less-known-parts-bitwise.html
// http://jsperf.com/bitwise-vs-math-object
// http://united-coders.com/christian-harms/results-for-game-for-forfeits-and-the-winner-is/
// https://mudcu.be/journal/2011/11/bitwise-gems-and-other-optimizations/
// https://dreaminginjavascript.wordpress.com/2009/02/09/bitwise-byte-foolish/
// http://jsperf.com/math-min-max-vs-ternary-vs-if/24
"use strict";
var PI = Math.PI;
@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 / 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 / COMP-3
Created August 21, 2015 13:54
Entendendo o comp 3 cobol
ENTENDENDO O FORMATO COMP-3
13 Comentarios |
Tweet
Prezados Leitores,
Este Post descreve como os dados são armazenados quando estão no formato COMP-3.
COMP-3 é um campo que coloca dois dígitos em cada byte, usando uma notação chamada Binary Coded Decimal, ou BCD. COMP-3 é um tipo de dado comum, mesmo fora do COBOL, e é bastante normal em plataformas - isto é, não é dependente do sistema operacional, língua, ou CPU. Contudo, COMP-3 não é comumente encontrado em linguagens de MICRO.
Como os dados são armazenados:
O Binary Coded Decimal (BCD) tipo de dados é tal como o nome sugere - é um valor armazenado em notação decimal (base dez), e cada dígito binário é codificado. Uma vez que um dígito só tem dez possíveis valores (0-9), pode ser representada em forma binária, com apenas 4 bits. Quatro bits é chamado de "nybble", e cada nybble contém um dígito do valor. Portanto, você pode obter dois dígitos em cada 8 bits byte. A representação normal de caracteres armazena apenas um caractere (dígito) por byte, isso
@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 / Mouse Linux Xmodmap X11 manual
Last active May 1, 2023 19:21
Mouse Linux Xmodmap X11
Somehow, I ended up without any xmodmap files on my Ubuntu install, so I had to find a different approach to this problem.
Take a look at the **xinput** command.
xinput list | grep -i mouse
which lists information about your mouse. It shows my mouse is "Dell Premium USB Optical Mouse" and also that I have "Macintosh mouse button emulation". Armed with that info, I can
xinput get-button-map "Dell Premium USB Optical Mouse"
@leodutra
leodutra / delete-recursively.bat
Last active May 1, 2023 19:09
Batch for deleting files and folders recursively on Windows.
@echo off
set foldername=%1
:: Remove files before removing their folders. It's faster
DEL /F /Q /S %foldername%\*
:: "RD" is much more fast than "RMDIR"
for /D %%i in ("%foldername%\*") do RD /S /Q "%%i"
@leodutra
leodutra / .xsessionrc
Created June 18, 2015 19:39
Lenovo Thinkpad E430 Ubuntu 14.04 keyboard layout slash fix pt-br
#!/bin/bash
# add this file to your /home
setxkbmap -model thinkpad60 -layout br
@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 / boot-setup.md
Created March 8, 2017 13:47
Bios boot type on GPT vs MBR boot flag
  • Legacy BIOS bootable attribute -- This is the official name of the relevant feature, as described in the UEFI specification (version 2.3.1, p. 105, Table 19). It's set by setting the "legacy_boot flag" in parted or its relatives, or by setting attribute bit #2 using the "a" option on the experts' menu in gdisk. (The wiki to which you linked describes doing this with sgdisk.) It's used by SYSLINUX's GPT support to identify a partition that holds second-stage boot code.
  • The "boot flag" on MBR disks -- On MBR disks, the "boot flag" is a bit that can be set using either fdisk or parted. It's analogous to the GPT legacy BIOS bootable attribute, since it serves the same purpose. Note that on a GPT disk, it's possible (although technically a violation of the spec) to set this flag on the protective 0xEE partition. You can do this with fdisk, but not with parted, since the latter lacks a user interface to do anything explicit with the protective 0xEE MBR partition. (This is reportedly changing with in-development