Skip to content

Instantly share code, notes, and snippets.

@aayla-secura
aayla-secura / resize-observer-ext.js
Last active June 14, 2024 10:15
Javascript Resize Observer wrapper with additions
// supports:
// - throttling by calling handler only once after a given delay has passed since the last resize
// - pausing and resuming (with or without calling callback at resume)
// - observing multiple targets and ensuring the handler is called only once all are added
// - observing targets without calling the handler initially when adding, only when later resized
class ResizeObserverExt {
observer = null;
#waitingResolver = null;
#targets = new Set();
@aayla-secura
aayla-secura / flex-auto-size-test.html
Last active June 9, 2024 12:42
Automatically calculate flex basis of text and image for equal height
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width" />
<title></title>
<script src="helpers.js" charset="utf-8"></script>
<script src="flex-auto-size.js" charset="utf-8"></script>
<style type="text/css" media="screen">
@aayla-secura
aayla-secura / getpaid-sync-related-items-stock.php
Last active June 7, 2023 01:41
GetPaid Wordpress plugin: Code snippet to synchronise the stock levels of related items (parents, children)
@aayla-secura
aayla-secura / getpaid-item-purchases.php
Last active June 6, 2023 21:33
GetPaid Wordpress plugin: Code snippet to list users who've purchased an item (or any of its children)
<?php
add_action( 'add_meta_boxes', 'add_getpaid_item_invoices_meta_box', 50 );
function add_getpaid_item_invoices_meta_box() {
add_meta_box( 'wpinv_item_invoices', __( 'Item Purchases', 'invoicing' ), 'show_getpaid_item_purchases', 'wpi_item', 'normal' );
}
function show_getpaid_item_purchases( $post ) {
// get this post and all children
$posts = get_children( array(
@aayla-secura
aayla-secura / getpaid-assign-user-roles.php
Last active June 6, 2023 21:33
GetPaid Wordpress plugin: Code snippet to assign user roles per subscription
<?php
function subscription_user_role_dbg_log( $data ) {
// error_log( print_r( $data, true ) );
}
function edit_member_role( $method, $subscription ) {
$roles = array(
// <name of item> => <slug of wordpress user role>
"Class Membership" => "class_member",
"Centre Membership" => "centre_member",
#!/usr/bin/env python3
import logging
import math
import string
import sys
import argparse
from collections.abc import Mapping, MutableMapping
from collections import Counter
import re
@aayla-secura
aayla-secura / rbash_funcs.sh
Last active June 11, 2021 00:45
Functions to do useful stuff in a restricted bash shell; Uses only bash built-ins
#!/bin/bash
# Uses only bash built-ins allowed in restricted mode
# Also includes a few functions that require some external commands, see
# FUNCTIONS THAT REQUIRE SOME EXTERNAL COMMANDS at the end
# TODO check for # of arguments; or an argument parser
function _echoarray {
# print array elements one per line
local IFS=$'\n'
echo "$*"
@aayla-secura
aayla-secura / hashcat_gen_username_rule.sh
Created April 23, 2021 01:11
Generate a hashcat rule file to prepend {username}: to every password
#!/bin/bash
usage() {
cat <<EOF
Takes a list of usernames a writes a rule file to prepend each of these to each password canditate.
${BASH_SOURCE[0]} <options> <username or file> [<username or file> ...]
Options:
-@ Also take the base username if full one is an email
@aayla-secura
aayla-secura / nasm_shell.sh
Last active March 10, 2021 21:19
Show disassembly of given opcodes or assembly instructions
#!/bin/bash
# See -h for help
INTERACTIVE=1
READ_ARGS=()
NASM_ARGS=()
OBJDUMP_ARGS=()
# Determine if interactive or stdin is redirected from file/heredoc/command
# output/etc
@aayla-secura
aayla-secura / jwt_bruteforce.py
Created January 19, 2021 00:18
Brute-force a JWT signed with a shared key
#!/usr/bin/env python3
#############################################################
# @AaylaSecura1138, github.com/aayla-secura
# Modify and distribute as you wish
#############################################################
import logging
import jwt
import sys
import argparse