Skip to content

Instantly share code, notes, and snippets.

View jackylamhk's full-sized avatar

Jacky Lam jackylamhk

View GitHub Profile
@jackylamhk
jackylamhk / write-random-data
Last active July 15, 2024 06:49
Write random data to disk
#!/bin/sh
set -euo pipefail
if [[ $# -lt 1 || $1 == "--help" ]]; then
echo "Usage: $0 <target_path> <size_in_gb> (default: 10)"
exit 0
fi
GiB_IN_BYTES=1073741824
@jackylamhk
jackylamhk / andotp_to_aegis.py
Last active July 15, 2024 05:44
Convert AndOTP JSON export to Aegis
#!/usr/bin/env python3
import logging
import sys
import json
import uuid
logger = logging.getLogger("andotp-to-aegis")
@jackylamhk
jackylamhk / aws_secrets.py
Created July 5, 2024 02:37
AWS Secrets Manager - Python
import logging
import os
import json
import httpx
logger = logging.getLogger(__name__)
class AWSSecretsConfig:
_TOKEN = os.environ.get("AWS_SESSION_TOKEN")
@jackylamhk
jackylamhk / set_aws_profile.sh
Last active February 18, 2024 01:23
Configure default AWS profile on GitHub Actions
export AWS_PROFILE=default
aws configure set region $AWS_DEFAULT_REGION --profile $AWS_PROFILE
aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID --profile $AWS_PROFILE
aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY --profile $AWS_PROFILE
aws configure set aws_session_token $AWS_SESSION_TOKEN --profile $AWS_PROFILE
unset AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SESSION_TOKEN AWS_REGION
@jackylamhk
jackylamhk / remove_admin_toolbar_items.php
Last active November 23, 2023 15:49
Remove Multisite admin menu bar items
// !! DO NOT DISABLE
// The WP Admin UI enumerates all sites so if this
// is disabled the UI will take forever to load
function remove_admin_toolbar_items( $bar ) {
$bar -> remove_node( 'wp-logo' );
// Remove "My Sites" item if not primary site
if (get_current_blog_id() != 1 ) {
$bar -> remove_node( 'my-sites' );
@jackylamhk
jackylamhk / deploy_o365_addin.py
Created November 13, 2023 13:41
Script to deploy add-ins to O365, using reversed engineered endpoints.
import logging
import re
import os
import sys
import xml
import json
import time
import httpx
import asyncio
import xmltodict
@jackylamhk
jackylamhk / sort_dict.py
Last active November 7, 2023 16:58
Sorting a big dict with recursion
def sort_dict(dictionary: dict) -> dict:
LIST_KEYS = ["priority", "clientId", "providerId", "clientScope", "alias", "name"]
def _get_list_sort_key(d: dict):
for key in LIST_KEYS:
if key in d:
return d[key]
return d[sorted(d.keys())[0]]
def _sort_dict(obj: any):
import httpx
import jwt
from json import JSONDecodeError
from datetime import datetime, timezone, timedelta
from urllib.parse import urlunsplit, urlencode
class InsidedAdminError(Exception):
pass
import logging
import httpx
from urllib.parse import urlunsplit, urlencode
logger = logging.getLogger(__name__)
class SkilljarAdminError(Exception):
pass
import secrets
import random
import string
# Source: https://www.geeksforgeeks.org/generating-strong-password-using-python/
def generate_password(length: int, use_symbols: bool = False):
ALL_CANDIDATES = string.ascii_letters + string.digits
password = [
secrets.choice(string.digits),