Skip to content

Instantly share code, notes, and snippets.

@geekley
geekley / NumberLimits.gd
Last active March 22, 2024 02:57
Numerical constants for limits of integers and IEEE 754 floats, defined as calculations of their exact values.
# Public domain, as per The Unlicense. NO WARRANTY. See https://unlicense.org
class_name NumberLimits
## Useful for dealing with numerical limits.
## Minimum positive 64-bit floating-point number > 0.
## [br]0x0000000000000001
const FLOAT64_MIN_SUBNORMAL: float = 2.0**-1074 # ≈ 4.9406564584124654e-324
## Maximum positive 64-bit floating-point subnormal number (min possible value in binary exponent).
## [br]0x000FFFFFFFFFFFFF
@geekley
geekley / NonJoypads.gd
Last active January 15, 2024 12:30
Fix false positives in Godot joypad device detection (e.g. touchpads). See https://github.com/godotengine/godot/issues/59250#issuecomment-1786196830
# Public domain, as per The Unlicense. NO WARRANTY. See https://unlicense.org
extends Node
## Solves a [url=https://github.com/godotengine/godot/issues/59250]bug[/url] where touchpad devices
## can be detected as a joypad.
##
## This script should be autoloaded in the project settings.
## This is merely a workaround, not for use in production code.
static var _Self: GDScript = (func() -> void:).get_object() as GDScript
@geekley
geekley / convert-image.desktop
Last active January 6, 2022 01:52
Convert images to a specified file format, like ico, png, etc., removing metadata. Uses ImageMagick's `mogrify` command. Add to `~/.local/share/applications/` on Ubuntu.
[Desktop Entry]
Name=Convert Image
GenericName=Image Converter
Comment=Convert images to a specified file format, like ico, png, etc.
Exec=bash -c 'x=$(zenity --title="Convert Images" --width=320 --entry --text="New file extension:" --entry-text=png) && mogrify -background transparent -strip -define icon:auto-resize=16,24,32,48,64,72,96,128,256 -format "$x" "$@"' "$0" %F
Icon=convert
Type=Application
Categories=Graphics;
StartupNotify=false
Terminal=false
@geekley
geekley / asciify-dic.sh
Last active January 6, 2022 01:41
Asciify a spell-check dictionary (word list). It filters words from a .dic with non-ascii chars and transforms the words into ascii-only versions. https://github.com/streetsidesoftware/cspell/issues/1060#issuecomment-1006199819
#!/usr/bin/env bash
#License: "Zero-Clause BSD" <https://opensource.org/licenses/0BSD>
# Requires perl and unidecode module (in Ubuntu, it can be installed with sudo apt install libtext-unidecode-perl).
# Example usage: asciify-dic $DIC_NAME.dic > $DIC_NAME-asciified.dic
if [[ "$1" == "--help" ]]; then
echo "Usage: $(basename "$0") INPUT_FILE > OUTPUT_FILE"
echo "Asciify a .dic file (list of dictionary words)."
echo ""
echo "Generates a file with ASCII-only versions of the words that have non-ASCII chars."
@geekley
geekley / portuguese-asciified.dic
Created January 6, 2022 00:19
An asciified Portuguese dictionary. This list of "words with accent removed" can be used in addition to the regular dictionary for accent-insensitive spell-checking.
This file has been truncated, but you can view the full file.
% List of asciified Portuguese words
% [Lista de palavras asciificadas em português]
%
% Generated from the complete list of words at:
% https://www.winedt.org/dict/portuguese.html
% https://www.winedt.org/dict/portuguese.zip
%
% License: GNU LGPL v2.1
% Credits to: Bernhard Enders, Raimundo Santos Moura, Ricardo Ueda Karpischek
%
@geekley
geekley / HashCode.cs
Last active August 14, 2018 17:45
A good implementation of GetHashCode in C#
V val; // struct
T obj; // class
V? nlv; // Nullable
X unk; // not known if class or struct
public override int GetHashCode() {
int h = 23;
unchecked {
h = (h << 5) - h + val.GetHashCode();
h = (h << 5) - h + (obj != null ? obj.GetHashCode() : 0);
h = (h << 5) - h + (nlv != null ? nlv.GetHashCode() : int.MinValue);
@geekley
geekley / ConvertToMinifiedPNG.reg
Created July 12, 2018 02:08
Installs a context menu entry on Windows to convert Inkscape SVG and PNG files to minified PNG (stripping metainfo and EXIF tags)
Windows Registry Editor Version 5.00
; Created with Default Programs Editor
; http://defaultprogramseditor.com/
; Add Verb
[HKEY_CURRENT_USER\Software\Classes\inkscape.svg\shell\ConvertToMinifiedPNG]
@="Convert to minified PNG"
[HKEY_CURRENT_USER\Software\Classes\inkscape.svg\shell\ConvertToMinifiedPNG\command]
@="\"C:\\Program Files\\ImageMagick\\7.0.3-Q16\\convert.exe\" -background none -strip -set filename:n \"%%t\" \"%1\" \"%%[filename:n].png\""