Skip to content

Instantly share code, notes, and snippets.

View winstxnhdw's full-sized avatar
⚠️
This user is a registered cybercriminal. Learn about GitHub Terms of Service.

Winston H. winstxnhdw

⚠️
This user is a registered cybercriminal. Learn about GitHub Terms of Service.
View GitHub Profile
@winstxnhdw
winstxnhdw / normalise_angle.py
Last active July 31, 2023 15:36
Normalises angle between -pi to pi.
from math import atan2, sin, cos
def normalise_angle(angle: float):
"""
Summary
-------
normalise an angle to the range [-pi, pi]
Parameters
@winstxnhdw
winstxnhdw / 1d_cosine_similarity.py
Last active July 31, 2023 15:34
Calculates the cosine similarity of a pair of 1D lists.
from numpy import float64, inner
from numpy.linalg import norm
from numpy.typing import NDArray
def calculate_1d_cosine_similarity(a: NDArray[float64], b: NDArray[float64]) -> float:
"""
Summary
-------
calculate the cosine similarity of two 1D vectors
@winstxnhdw
winstxnhdw / calculate_profile.py
Last active July 11, 2023 01:54
Calculates yaw and curvature of a 2D line with forward difference.
from numpy import ediff1d, concatenate, arctan2, ndarray
from numpy.typing import ArrayLike
def solve_1st_derivative(x: ArrayLike, y: ArrayLike) -> tuple[ndarray, ndarray]:
"""
:param x: (ArrayLike) x-coordinates of the 2D line [m]
:param y: (ArrayLike) y-coordinates of the 2D line [m]
@winstxnhdw
winstxnhdw / 2d_linear_interpolator.py
Last active July 31, 2023 15:33
Linear interpolation of a 2D line with SciPy.
from numpy import arange, array, concatenate, cumsum, ediff1d, float64, hypot
from numpy.typing import NDArray
from scipy.interpolate import interp1d
def linear_interpolation(
x: NDArray[float64],
y: NDArray[float64],
linear_displacement: float
) -> tuple[NDArray[float64], NDArray[float64]]:
@winstxnhdw
winstxnhdw / cv_region_crop.py
Last active November 6, 2022 21:40
Get the coordinates of any screenshot with PyScreeze and OpenCV.
import cv2 as cv
from numpy import asarray, ndarray
from pyscreeze import screenshot
IntVector2 = tuple[int, int]
class NoRegionSelected(Exception):
"""Raised when the user ends the selection without selecting a region."""
@winstxnhdw
winstxnhdw / car_description.py
Last active October 24, 2023 18:54
Possibly the fastest description of a car for visualising vehicle control in Matplotlib with only NumPy.
from math import cos, sin
from typing import NamedTuple
import numpy as np
from numpy.typing import NDArray
class Vertices(NamedTuple):
"""
Summary
@winstxnhdw
winstxnhdw / birdshit_begone.py
Last active October 20, 2022 15:52
Twitter bot that automatically sends all your cringey tweets to oblivion.
import tweepy
from traceback import print_exc
from re import sub
def oauth_login(consumer_key, consumer_secret):
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth_url = auth.get_authorization_url()
@winstxnhdw
winstxnhdw / edit_with_neovim_for_wt.reg
Last active December 24, 2022 16:42 — forked from JAffleck/editWithNeoVIm.reg
Adds "Edit with Neovim" to the Windows 10 context menu for the Windows Terminal. See original fork for Neovim-qt instead.
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\*\shell\Neovim]
@="Edit with Neovim"
"Icon"="C:\\tools\\neovim\\Neovim\\bin\\nvim-qt.exe"
[HKEY_CLASSES_ROOT\*\shell\Neovim\command]
@="wt new-tab PowerShell nvim (Get-Item -LiteralPath %1).FullName"
@winstxnhdw
winstxnhdw / ScreenshotManager.cs
Last active October 14, 2022 10:02
A screenshot manager that evades image overwriting for Unity. Take a screenshot with the PrintScreen key and save it in Documents/<ApplicationName>/Screenshots/<Index>.png. Unfortunately, it only supports up to 18,446,744,073,709,551,615 screenshots.
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
// Only supports up to 18,446,744,073,709,551,615 screenshots
public class ScreenshotManager : MonoBehaviour {
const string DirectoryName = "Screenshots";
@winstxnhdw
winstxnhdw / SoftClipping.cs
Last active August 30, 2022 22:00
Fades a canvas in when the camera is near; fades a canvas out when the camera is too far. No shaders required. Attach script to Canvas with a CanvasGroup component.
using System;
using UnityEngine;
// Fades a canvas in when the camera is near.
// Fades a canvas out when the camera is too far.
[RequireComponent(typeof(CanvasGroup))]
public class SoftClipping : MonoBehaviour {
const float maxAlpha = 1.0f;
const float maxViewDistance = 4.0f;
const float fadeInDistance = 2.0f;