Skip to content

Instantly share code, notes, and snippets.

View amotl's full-sized avatar

Andreas Motl amotl

  • $PYTHONPATH
View GitHub Profile
@amotl
amotl / grafana-prometheus-query-samples.md
Last active March 10, 2024 00:29
Grafana Prometheus query expression samples

About

A few samples of Prometheus queries in Grafana dashboards.

Details

{
  "datasource": {
    "type": "prometheus",
@amotl
amotl / example_jmespath_paxcounter_kotori.py
Last active June 9, 2023 09:59
Select most recent `pax` measurement values from ESP32-Paxcounter devices recording data using the Kotori data historian.
# About
# =====
# Select most recent `pax` measurement values from ESP32-Paxcounter
# devices recording data using the Kotori data historian.
#
# Synopsis
# ========
#
# pip install jmespath requests
# python3 example_jmespath_paxcounter_kotori.py "https://swarm.hiveeyes.org/api/hiveeyes/zku/paxcounter/bauschilderung/data.json?from=now-5m"
@amotl
amotl / cratedb_pandas_insert.py
Created April 1, 2023 13:02
Demonstrate efficient batched inserts using CrateDB and pandas
"""
About
=====
Example program to demonstrate efficient batched inserts using CrateDB and
pandas, based on SQLAlchemy's "insertmanyvalues" and CrateDB's bulk import
HTTP endpoint.
- https://docs.sqlalchemy.org/core/connections.html#controlling-the-batch-size
- https://crate.io/docs/crate/reference/en/5.2/interfaces/http.html#bulk-operations
@amotl
amotl / example_sa_orm_rowcount.py
Last active March 21, 2023 14:30
Evaluate `.rowcount` attribute on DELETE queries with SQLAlchemy ORM 1.3, 1.4 and 2.0.
"""
Evaluate `.rowcount` attribute on DELETE queries with SQLAlchemy ORM 1.3, 1.4 and 2.0.
docker run --rm -it --publish=4200:4200 crate
pip install 'sqlalchemy<1.4' --upgrade
pip install 'sqlalchemy<1.5' --upgrade
pip install 'sqlalchemy<2.1' --upgrade
python example_sa_orm_rowcount.py
@amotl
amotl / example_sa_rowcount.py
Last active March 21, 2023 14:23
Evaluate `.rowcount` attribute on DELETE queries with SQLAlchemy 1.3, 1.4 and 2.0
"""
Evaluate `.rowcount` attribute on DELETE queries with SQLAlchemy 1.3, 1.4 and 2.0.
docker run --rm -it --publish=4200:4200 crate
python example_sa_rowcount.py
"""
import sqlalchemy as sa
try:
from sqlalchemy.orm import declarative_base, sessionmaker
@amotl
amotl / sqlalchemy_efficient_inserts.py
Last active March 10, 2024 00:29
Demonstrate multi-row inserts and batched inserts using SQLAlchemy's "insertmanyvalues_page_size" option.
"""
About
=====
Example program to demonstrate multi-row inserts and batched inserts
using SQLAlchemy's "insertmanyvalues_page_size" option.
https://docs.sqlalchemy.org/core/connections.html#controlling-the-batch-size
Synopsis
@amotl
amotl / example_cratedb_dask.py
Last active May 11, 2023 10:54
Evaluate saving Dask DataFrames into CrateDB.
"""
About
=====
Evaluate saving Dask DataFrames into CrateDB.
Usage
=====
::
@amotl
amotl / asyncpg_psycopg3.diff
Last active March 7, 2023 20:35
Difference between test cases for CrateDB using "asyncpg" vs. "psycopg3"
--- tests/client_tests/python/asyncpg/test_asyncpg.py 2023-03-07 21:33:30.000000000 +0100
+++ tests/client_tests/python/psycopg3/test_psycopg3.py 2023-03-07 21:33:30.000000000 +0100
@@ -1,14 +1,15 @@
"""
About
=====
-Test cases for CrateDB using `asyncpg`.
+
+Test cases for CrateDB using `psycopg3` [1,2].
@amotl
amotl / pypi2git.py
Created March 7, 2023 00:54
Download all versions from PyPI and spool them into Git repository.
"""
Download all versions from PyPI and spool them into Git repository.
pip install click GitPython requests
"""
import shutil
import tempfile
from distutils.version import LooseVersion
from pathlib import Path
@amotl
amotl / example_psycopg_server_cursor.py
Last active March 28, 2023 13:20
Evaluate CrateDB server-side cursors with psycopg3.
"""
About
=====
Evaluate CrateDB server-side cursors with `psycopg3`.
- https://crate.io/docs/crate/reference/en/5.2/sql/statements/declare.html
- https://crate.io/blog/feature-focus-working-with-cursors-with-sql-commands
Introduction
============