Skip to content

Instantly share code, notes, and snippets.

View alanbchristie's full-sized avatar

Alan B. Christie alanbchristie

View GitHub Profile
@alanbchristie
alanbchristie / token-demo.py
Created June 6, 2024 13:49
Simplified API token-demo (Fragalysis)
#! /usr/bin/env python
#
# A simplified 'token-demo'.
# Driven by a number of envieonment variables,
# this code example illustrates the extraction of a token from the Stack keycloak server
# and then the invokation of a (non-CSRF) API endpoint using that toekn.
#
# Tested with Python 3.12.3 and requires 'requests' (and tested with 2.32.2).
# Last tested 6th June 2024 against the legacy Fragalysis Stack.
@alanbchristie
alanbchristie / notes.txt
Created March 19, 2024 23:39
LibreTranslate
Installed on a RPi 5 (libre-translate.local/192.168.0.6)
To create API keys enter the container: -
docker exec -it <container> bash
The use 'ltmanage' to list the keys: -
./venv/bin/ltmanage keys
@alanbchristie
alanbchristie / borg_code.py
Last active February 11, 2024 12:16
Code generator for key code locks from BorgLocks
#!/usr/bin/env python3
"""Simple class to generate keypad codes for Borg door locks.
Run this code to generate random 4 and 5 digit codes.
Each random code is generated once with, and once without using the X and Z buttons.
See https://borglocks.co.uk
"""
import random
@alanbchristie
alanbchristie / git_query.py
Last active January 23, 2024 12:04
Querying a repository with GitPython
#!/usr/bin/env python3
# Here we assume you've installed the GitPython package
# and you're running this code from a repository clone.
from typing import Optional
from git import Repo
from git.refs.tag import TagReference
repo: Repo = Repo()
@alanbchristie
alanbchristie / kc-users.sh
Last active July 14, 2023 15:22
Getting keycloak users with httpie and jq
# Get username and emails from a Keycloak realm
# assuming you've installed httpie and jq
#
# - https://httpie.io
# - https://jqlang.github.io/jq/
# Armed with a keycloak URL
# And realm and realm manager password
URL=example.com
REALM=blob
{
"folders": [
{
"path": "squonk2-python-cl-tools"
},
{
"path": "squonk2-admin"
},
{
"path": "squonk2-deck"
{
"folders": [
{
"path": "Diamond/fragalysis-backend"
},
{
"path": "Diamond/dls-fragalysis-stack-kubernetes"
},
{
"path": "Diamond/fragalysis-stack"
@alanbchristie
alanbchristie / token-demo.py
Last active July 26, 2023 14:14
API access to a Token-based REST service (Python/requests)
#! /usr/bin/env python
import os
import base64
# Use the Python requests module
# (you'll need to have PIP-installed this - it's not part of core Python)
import requests
# The keycloak credentials (sensitive).
@alanbchristie
alanbchristie / dm-job.code-workspace
Created December 21, 2022 08:30
VS Code Job Workspace file
{
"folders": [
{
"path": "squonk2-data-manager-job-tester"
},
{
"path": "squonk2-data-manager-job-decoder"
},
{
"path": "squonk2-data-manager-job-utilities"
@alanbchristie
alanbchristie / as.code-workspace
Last active December 21, 2022 08:15
VS Code AS Workspace file
{
"folders": [
{
"path": "squonk2-account-server.wiki"
},
{
"path": "squonk2-account-server"
},
{
"path": "squonk2-account-server-ansible"