Skip to content

Instantly share code, notes, and snippets.

@laundmo
laundmo / main.rs
Created May 9, 2025 13:16
bevy camera 2d drag/zoom with picking observers
use bevy::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_systems(Startup, setup)
.run();
}
fn setup(mut commands: Commands, window: Single<Entity, With<Window>>) {
commands.spawn(Camera2d);
commands.entity(*window).observe(camera_drag).observe(zoom);
@laundmo
laundmo / noita.kwinrule
Created March 11, 2025 00:27
Noita KDE Wayland Adaptive Sync ghosting artifact fix
[Noita]
Description=Noita
adaptivesyncrule=2
wmclass=steam_app_881100
wmclassmatch=1
@laundmo
laundmo / py4web_template_formatter.md
Last active February 17, 2025 17:18
py4web template language formatter using djlint

A script which formats py4web templates using DJLint, by partially converting them to Django syntax and back.

How to use:

  1. Install DJLint: py -m pip install djlint
  2. Download the script
  3. Run the script with a template file: py template_formatter.py ./templates/mytemplate.html

Auto-format on save in VSCode:

  1. Get the Run On Save extension
  2. If you have a venv, configure it like this. (assumes venv is located in: ./.venv - if its not, or on another OS, adjust paths accordingly.)
@laundmo
laundmo / hover_zoomable.js
Last active December 6, 2024 20:57
JS function which makes a html image zoomable by hovering over it. Licensed MIT
/**
* Makes an HTML image zoomable on hover. Requires the img to be nested in a container of the same size.
* Uses transform for the actual zoom behaviour.
*
* @param {HTMLElement} elem - The HTML element of the image to make zoomable.
* @param {number} scale - The zoom scale factor.
* @param {number} [margin=0.2] - The margin around the zoomed image, as a fraction of the image. Helps with seeing the edges.
* @returns {void}
*
* @example
from typing import Dict, Any, DefaultDict, Optional, TYPE_CHECKING
from collections import defaultdict
if TYPE_CHECKING:
TreeDict = Dict[Any, Union[Any, "TreeDict"]]
TreeDefaultDict = DefaultDict[Any, Union[Any, "TreeDefaultDict"]]
def tree_dict_factory(nested_dict: Optional["TreeDict"] = None) -> "TreeDefaultDict":
"""
@laundmo
laundmo / random_outside.rs
Created August 25, 2024 05:22
generate random points outside the screen bevy
use bevy::prelude::*;
use rand::{thread_rng, Rng};
fn main() {
App::new()
.insert_resource(ClearColor(Color::srgb(1.0, 0.0, 0.0)))
.add_plugins(DefaultPlugins)
.add_systems(Startup, setup)
.add_systems(Update, point_out)
.run();
@laundmo
laundmo / triple.py
Last active November 16, 2024 00:55
largest pythagoras triple which fits in 10000 chars
# theory: starting at 3,4,5 use the "maximise" function to compute what a multiple of this triple exactly inside the limit looks like
# this is far from a ideal triple, as the quotient of a/b closer to 1 means a more ideal triple starting point (triangle sides which are the most equal possible)
# so we generate all triples with a, b=a+1, c using the method described in this link:
# https://math.stackexchange.com/questions/3399189/looking-for-the-best-way-to-find-pythagorean-triples-where-b-a-pm1
# then we maximise the found triple and check whether its product is larger than the previous largest
# we stop once all triples which unmaximised fit into the limit have been checked, as any larger ones can't be used anyways
# largest value which will fit
limit = int("9" * 10_000)
@laundmo
laundmo / a_copy_sig.py
Last active February 18, 2025 18:35
Copy a functions/methods signature for typing without specifying each individual argument type
# this needs only a single line, besides imports! only tested with pyright/pylance.
# downside: no functools.wraps, at runtime __doc__ etc. will be wrong
from functools import partial, wraps
from typing import cast
# just copy this and replace "otherfunc" with the function you want to copy from
@partial(cast, type(otherfunc))
def myfunc(*args, **kwargs):
return otherfunc(*args, **kwargs)
@laundmo
laundmo / lerp.rs
Created December 28, 2023 14:47
lerp, inverse_lerp and remap in Rust
trait Lerp<T> {
fn lerp(self, from: T, to: T) -> T;
fn inv_lerp(self, from: T, to: T) -> T;
fn remap(self, from_range: (T, T), to_range: (T, T)) -> T;
}
macro_rules! lerp_impl {
($one:literal, $typ:ty) => {
impl Lerp<$typ> for $typ {
#[inline(always)]
@laundmo
laundmo / stylus.css
Created November 24, 2023 21:53
twitch table layout
.tw-tower {
flex-flow: row wrap;
flex-direction: column;
}
.tw-tower article {
flex-direction: row-reverse !important;
}
.tw-tower article > div > div > div {