Skip to content

Instantly share code, notes, and snippets.

View charbonnierg's full-sized avatar

Guillaume Charbonnier charbonnierg

  • Araymond
  • Grenoble
  • 13:13 (UTC +02:00)
View GitHub Profile
@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
@charbonnierg
charbonnierg / empty.py
Last active April 23, 2023 18:52
An Empty class to use with Pydantic
"""
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
@charbonnierg
charbonnierg / pydantic_parser.py
Last active May 11, 2023 09:55
Pydantic models parser
"""
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
@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 / 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:

Build Python

Build & install the python version of your choice quicky on Ubuntu 20.04:

curl -sL https://gist.githubusercontent.com/charbonnierg/fc805149c83f239f70dab055d409e868/raw/build-python.sh | sudo bash -s 3.10.13

Notes

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".)

"""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.'''
@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

blemonitor

Monitor BLE devices using Bluez and D-Bus.

Requirements

  • Bluez >= 5.56
  • Linux Kernel >= 5.10

Questions