Skip to content

Instantly share code, notes, and snippets.

@manstie
manstie / dom-search.ts
Last active May 30, 2024 02:07
Manual search highlighting
search(elements: HTMLElement[], value: string) {
value = value.toLowerCase();
for (const el of elements) {
el
.querySelectorAll('mark')
.forEach((highlight) => {
highlight.outerHTML = highlight.textContent || '';
});
// make text nodes homogeneous again on firefox
@manstie
manstie / app_error.rs
Last active February 9, 2024 04:02
Generic Axum Error Handler
use axum::{
http::StatusCode,
response::{IntoResponse, Response},
};
use std::{fmt, panic::Location};
// Make our own error that wraps all errors
pub struct AppError {
inner: Box<dyn std::error::Error>,
location: &'static Location<'static>,
@manstie
manstie / TrimAllWhitespace.php
Last active July 19, 2024 09:35
Trim all whitespace
/**
* Trims https://invisible-characters.com/
*/
function trimAllWhitespace(string $str): string
{
return trim($str, "\u{0000}..\u{002D}\u{007F}..\u{00A0}\u{00AD}\u{034F}\u{061C}\u{115F}\u{1160}\u{17B4}\u{17B5}\u{180E}\u{2000}..\u{200F}\u{202F}\u{205F}..\u{2064}\u{206A}..\u{206F}\u{3000}\u{2800}\u{3164}\u{FEFF}\u{FFA0}\u{1D159}\u{1D173}..\u{1D17A}\u{E0000}..\u{E007F}");
}
@manstie
manstie / hash.sh
Created August 27, 2021 07:54
Create a "correctly hashed certificate directory"
shopt -s extglob
shopt -s nullglob
for i in *.[0-9]; do
rm $i
done
# create a hashed directory for ssl use
for i in *.@(cer|crt|pem); do
hash=`openssl x509 -hash -noout -in $i`