Skip to content

Instantly share code, notes, and snippets.

View jackylamhk's full-sized avatar

Jacky Lam jackylamhk

View GitHub Profile
@jackylamhk
jackylamhk / k3s-rpi-guide.md
Created August 20, 2023 14:54
Guide to installing k3s on a Raspberry Pi

Guide to installing k3s on a Raspberry Pi

I'm creating this guide as I cannot find an updated guide anywhere that contains these specific series of steps needed to properly install k3s on a Raspberry Pi. In this case, I'm choosing to go with Ubuntu Server 23.04.

Steps

  1. Flash your microSD card with the Rasperry Pi Imager. Select Ubuntu Server 23.04 (64-bit) under OS.

    The imager also includes a cloud init config via the UI - which can help you set up the hostname and pre-authorize SSH keys. Note: If you confiure wireless LAN here, you will need to manually set up eth0 with netplan.

@jackylamhk
jackylamhk / atlassian_remove_inactive_licenses.py
Created November 6, 2023 15:04
Remove inactive licenses assignments for Atlassian
import logging
import httpx
import json
import asyncio
from datetime import datetime, timedelta, timezone
from urllib.parse import urlparse
logger = logging.getLogger()
logging.basicConfig(level=logging.DEBUG)
@jackylamhk
jackylamhk / converters.py
Last active November 15, 2023 17:37
Converting between camelCase and snake_case. Useful for communicating with APIs written in other languages.
"""
This module is created as Keycloak is written in Java, and I am not
succubming to Java or JavaScript's naming convention. #fuckthefrontend -J
Inspired by @sanders41/camel-converter
"""
def to_snake(string: str):
"""
Converts strings in camelCase or PascalCase to snake_case.
import logging
import requests
import json
import msal
from urllib.parse import urlencode
from email.mime.multipart import MIMEMultipart
from helpers import cypto
from helpers.config import AppConfig
logger = logging.getLogger(__name__)
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),
import logging
import httpx
from urllib.parse import urlunsplit, urlencode
logger = logging.getLogger(__name__)
class SkilljarAdminError(Exception):
pass
import httpx
import jwt
from json import JSONDecodeError
from datetime import datetime, timezone, timedelta
from urllib.parse import urlunsplit, urlencode
class InsidedAdminError(Exception):
pass
@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):
@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 / 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' );