Skip to content

Instantly share code, notes, and snippets.

View PsychedelicShayna's full-sized avatar
🐇
Writing Code & Contemplating Existence

Shayna PsychedelicShayna

🐇
Writing Code & Contemplating Existence
View GitHub Profile
@PsychedelicShayna
PsychedelicShayna / md5.rs
Last active May 10, 2024 03:18
A condensed, 358 line MD5 implementation for Rust, easy to copy paste into other projects.
pub mod md5 {
use std::convert::TryInto;
use std::fmt::Display;
use std::{fs::File, io::Read};
pub const BLOCK_LENGTH: usize = 64;
pub const DIGEST_LENGTH: usize = 16;
#[rustfmt::skip]
pub const INITIAL_STATE: [u32; 4] = [
@PsychedelicShayna
PsychedelicShayna / extract.rs
Last active January 5, 2024 23:46
Basically, for when Regex is overkill and you just want to extract substrings between deterministic start and end patterns. This Rust function will find every occurrence of a matching start/end pattern and return the contents in between.
pub fn extract(input: &str, pattern_start: &str, pattern_end: &str) -> Vec<String> {
let mut matches = Vec::new();
let mut position = 0;
while let Some(match_index) = input[position..].find(pattern_start) {
let start_index = position + match_index;
position = start_index + pattern_start.len();
if let Some(match_index) = input[position..].find(pattern_end) {
let end_index = position + match_index;
@PsychedelicShayna
PsychedelicShayna / eureka.py
Created December 26, 2023 13:10
A shitty idea basket script that I cooked up in 5 minutes, a temporary solution until I settle on a real utility.
#!/usr/bin/env python
import subprocess
import datetime
import random
import sys
import os
EUREKA_REPOSITORY: str = os.environ.get("EUREKA_REPO_PATH") or os.path.expanduser("~/eureka")
@PsychedelicShayna
PsychedelicShayna / hashmap_macro.rs
Last active January 4, 2024 19:06
A versatile map! macro I came up with as an analogue to vec! but for HashMaps, with added powers for quality of life in Rust.
use std::collections::HashMap;
#[macro_export]
macro_rules! map (
// -----------------------------------------------------------------------
// Inferred types, no bindings.
{$($key:expr => $value:expr;)+} => {
vec![
$(
($key, $value),
@PsychedelicShayna
PsychedelicShayna / zero_rand_decimal_places.py
Created December 16, 2023 23:41
Generates a random floating point zero, with N decimal places randomized between a lower (L) and upper (U) bound.
def zero_rand_places(n: int = 5, l: int = 4, u: int = 5) -> float:
'''
Generates a random floating point zero, with n decimal places between
0.1 and 0.9, with l and u clamping the lower and upper bounds of the
number, e.g. with l = 4, u = 5, n = 3: 0.400 <= R <= 0.599
'''
lb: int = 0.1 * 10**n
ub: int = 0.1 * 10 ** (n + 1) - 1
@PsychedelicShayna
PsychedelicShayna / str_abbr_hash.py
Last active November 13, 2023 16:06
This is a sort of rudimentary concise language-agnostic esoteric word hashing algorithm that's easy to copy+paste into existing code, not designed to obfuscate the word, and with no regards to collision prevention.
'''
This is a sort of rudimentary concise language-agnostic esoteric word hashing algorithm that's easy to copy+paste
into existing code, not designed to obfuscate the word, and with no regards to collision prevention.
Condenses words down to 4 characters, pads words less than 4 characters, retains its ability to be identified
as a same-length string, with knowledge of the original set, and that the machine can also use, for example,
to compute an offset in a contiguous array, among other things.
'''
def str_abbr(input: str, limit: int = 4, pad: str = '.') -> str | None:
@PsychedelicShayna
PsychedelicShayna / pacman-nuclear-gpg-fix.sh
Last active November 7, 2023 15:05
Fixes pacman GPG problems (e.g: "no pulic key") by rebuilding /etc/pacman.d/gnupg
#!/bin/sh
## Sometimes pacman enters a corrupted state where it cannot
## download any packages due to no public key being present
## to self-sign the archlinux certificates.
##
## This script fixes and reconstructs /etc/.pacman.d/gnugp
## Tested exclusively on Arco Linux; the results may be
## unpredictable on a non-Arco/Arch distro, e.g.
## Endeavor, Manjaro, etc..
@PsychedelicShayna
PsychedelicShayna / typedef.rs
Created October 18, 2023 22:14
Because seriously, why is `type` the only approximate keyword when it just acts like a #define? How about an actual type definition?
macro_rules! typedef {
($name:ident, $type:ty) => {
#[derive(Debug, Clone)]
struct $name($type);
impl From<$type> for $name {
fn from(value: $type) -> Self {
$name(value)
}
}
@PsychedelicShayna
PsychedelicShayna / repetition.reg
Created September 7, 2023 13:54
A backup of my preferences and a reference for others; overriding key repeat speeds on Windows to be speedier, especially with Vim.
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Control Panel\Accessibility\Keyboard Response]
"AutoRepeatDelay"="250"
"AutoRepeatRate"="6"
"BounceTime"="0"
"DelayBeforeAcceptance"="0"
"Flags"="59"
"Last BounceKey Setting"=dword:00000000
"Last Valid Delay"=dword:00000000