Skip to content

Instantly share code, notes, and snippets.

Avatar

Stefaan Lippens soxofaan

View GitHub Profile
@soxofaan
soxofaan / README.md
Last active Feb 15, 2021
Poor man's jq
View README.md

jq is a command line tool to process JSON documents with loads of features.

If you just want quick (re-)indentation, use one of these Python powered poor man's alternatives:

python -c "import json,sys;json.dump(json.load(sys.stdin),sys.stdout,indent=2)" < data.json

python -c "import json,sys,pprint;pprint.pprint(json.load(sys.stdin))" < data.json
@soxofaan
soxofaan / pyrasite-stacktrace-how-to.md
Last active Feb 9, 2021 — forked from reywood/how-to.md
How to get a stack trace from a stuck/hanging python script
View pyrasite-stacktrace-how-to.md

How to get a stack trace for each thread in a running Python script

Sometimes a Python script will simply hang forever with no indication of what is going wrong. Perhaps it's polling a service that will never return a value that allows the program to move forward.

Here's a way to see where the program is currently stuck, using pyrasite a tool for injecting code into running Python processes.

Install gdb and pyrasite

Install gdb.

@soxofaan
soxofaan / README.md
Last active Feb 4, 2021
Simple pretty CSV and TSV file viewer.
View README.md
@soxofaan
soxofaan / ignore_order.py
Last active Nov 3, 2020
Order ignoring list/tuple comparison asserts for pytest
View ignore_order.py
from typing import Union
class IgnoreOrder:
"""
pytest helper to test equality of lists/tuples ignoring item order
E.g., these asserts pass:
>>> assert [1, 2, 3, 3] == IgnoreOrder([3, 1, 2, 3])
>>> assert {"foo": [1, 2, 3]} == {"foo": IgnoreOrder([3, 2, 1])}
@soxofaan
soxofaan / dict_item.py
Created Oct 28, 2020
Python descriptor for attribute-like access in dict subclasses
View dict_item.py
class dict_item:
"""
Create an attribute in a custom dict subclass that accesses
the dict value keyed by the attribute's name:
>>> class UserInfo(dict):
>>> name = dict_item()
>>> age = dict_item()
>>> user = UserInfo(name="John")
>>> print(user.name)
@soxofaan
soxofaan / ensure_pyspark_executor_logging.py
Created Apr 7, 2020
Decorator based trick to enable Python logging from PySpark executors
View ensure_pyspark_executor_logging.py
import functools
import logging
import pyspark
from typing import Callable
LOG_FORMAT = "[P%(process)s/%(name)s] %(levelname)s: %(message)s"
def ensure_executor_logging(
f=None, *,
@soxofaan
soxofaan / openeo-mask-example.ipynb
Last active Mar 27, 2020
openeo-mask-example.ipynb
View openeo-mask-example.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@soxofaan
soxofaan / Issue107-graph-merging.ipynb
Created Feb 10, 2020
openeo python client issue #107 example
View Issue107-graph-merging.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View openeo-mask-example.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View luca-d22.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.