Skip to content

Instantly share code, notes, and snippets.

View charbonnierg's full-sized avatar

Guillaume Charbonnier charbonnierg

  • Araymond
  • Grenoble
  • 09:43 (UTC +02:00)
View GitHub Profile

blemonitor

Monitor BLE devices using Bluez and D-Bus.

Requirements

  • Bluez >= 5.56
  • Linux Kernel >= 5.10

Questions

@charbonnierg
charbonnierg / squid.conf
Created March 18, 2024 13:26
Squid conf
http_port 3128
refresh_pattern -i .rpm$ 129600 100% 129600 refresh-ims override-expire
refresh_pattern -i .iso$ 129600 100% 129600 refresh-ims override-expire
refresh_pattern -i .deb$ 129600 100% 129600 refresh-ims override-expire
refresh_pattern -i .whl$ 129600 100% 129600 refresh-ims override-expire
refresh_pattern ^ftp: 1440 20% 10080
refresh_pattern ^gopher: 1440 0% 1440
refresh_pattern -i (/cgi-bin/|\?) 0 0% 0
refresh_pattern . 0 20% 4320
"""Usage:
def get_listener(request: Request) -> Listener:
'''Function used to access listener from the application state.'''
return request.app.state.listener
def set_listener(app: FastAPI, url: str) -> None:
'''Function to be called once on application startup.'''

Install azure-cli (ansible task file)

This gist describes how to install azure-cli with Ansible.

Disclaimer: Code has not been tested so it may not work, but the intent is still clear.

Reference: Azure/azure-cli#20476 (note that issue has been opened by an engineer working at Microsoft on Azure CLI, so I take it as "it's ok to install azure-cli with pip assumning you don't have problem with using Pypi".)

@charbonnierg
charbonnierg / nats-cli-cheatsheet.md
Last active December 22, 2023 10:51
NATS CLI Cheatsheet

NATS Cheatsheet

Cheat sheets are available from the CLI directly:

nats cheat

Try out the following commands:

@charbonnierg
charbonnierg / clear-rbac.sh
Created September 3, 2023 12:05
Remove Azure RBAC with unknown user
#!/usr/bin/env bash
set -euo pipefail
ROLES=$(az role assignment list --query '[].{id:id, principalName:principalName}' --all)
IDS=$(echo $ROLES | jq -r '.[] | select(.principalName == "") | .id')
for ID in $IDS; do
echo "Removing role with unknown user: $ID"
az role assignment delete --ids "$ID" &
@charbonnierg
charbonnierg / README.md
Last active December 9, 2022 15:55
Python IoT Hub

Python IoT Hub

This gist is an attempt to design a Python API to implement a distributed IoT solution composed of:

  • Several IoT Device and Station backends (Examples: (BLEDevice, BLEStation), (OPCUADevice, OPCUAStation), ...)
  • A single IoT Gateway implementation, which can be deployed as different instances, potentially running different backends.
  • A single IoT Hub service running somewhere in the cloud
  • A single IoT Hub client implementation which can be used by Python developers
  • Two wrappers RemoteDevice and RemoteStation useful when interacting with IoT devices and stations
#!/usr/bin/env bash
function natsConf() {
echo -e "websocket {
# Specify a host and port to listen for websocket connections
host: localhost
port: 10443
no_tls: true
}
@charbonnierg
charbonnierg / oidc.py
Last active September 25, 2022 10:01
OIDC Authenticator
"""
Two classes:
- OIDCAuthenticator
- OIDCClientAuthenticator
Dependencies:
- PyJWT: API to decode JWT tokens
- cryptography: Cryptography algorithms
- pydantic: JSON validation library
- httpx: Async HTTP client
@charbonnierg
charbonnierg / asgi-with-static-files.py
Last active June 22, 2022 17:29
Server static files along a FastAPI application using starlette
import os
from pathlib import Path
from typing import Callable, Optional
from fastapi import FastAPI
from starlette.applications import Starlette
from starlette.routing import Mount
from starlette.staticfiles import StaticFiles
from starlette.types import Scope