Skip to content

Instantly share code, notes, and snippets.

View luzfcb's full-sized avatar

Fábio C. Barrionuevo da Luz luzfcb

View GitHub Profile
@luzfcb
luzfcb / gist:51aecde6bf303170c1d25a70ec94e7b7
Last active May 7, 2024 16:15
netdata docker start without telemetry
mkdir -p /etc/netdata/
touch /etc/netdata/.opt-out-from-anonymous-statistics
docker run -d --name=netdata \
--pid=host \
--network=host \
-v /etc/netdata:/etc/netdata \
-v netdatalib:/var/lib/netdata \
-v netdatacache:/var/cache/netdata \
-v /etc/passwd:/host/etc/passwd:ro \

show me 20 different uses of the tee function of the python itertools library

Chat GPT:

Certainly! The tee function in the Python itertools library is used to create independent iterators from a single iterable. Here are 20 different uses of the tee function:

  1. Splitting an iterable into two independent iterators:
from itertools import tee
@luzfcb
luzfcb / nvme_temps
Created October 12, 2022 18:06
extract nvme ssd temperatures
#!/usr/bin/env python3
import sys
import getpass
import json
from io import StringIO
try:
import sh
except ImportError:
print("Please, install the sh library http://amoffat.github.io/sh/#installation")
#!/bin/bash
set -o errexit
set -o pipefail
set -o nounset
postgres_ready() {
python << END
import sys
@luzfcb
luzfcb / invalidate_cached_property.py
Last active October 7, 2022 00:31
Invalidate cached_property
from functools import cached_property as functools_cached_property
try:
from django.utils.functional import cached_property as django_cached_property
except ImportError:
cached_property_classes = (
functools_cached_property,
)
else:
cached_property_classes = (
@luzfcb
luzfcb / drf_utils.py
Created April 29, 2022 13:26 — forked from twidi/drf_utils.py
Make Django Rest Framework correctly handle Django ValidationError raised in the save method of a model
"""
Sometimes in your Django model you want to raise a ``ValidationError`` in the ``save`` method, for
some reason.
This exception is not managed by Django Rest Framework because it occurs after its validation
process. So at the end, you'll have a 500.
Correcting this is as simple as overriding the exception handler, by converting the Django
``ValidationError`` to a DRF one.
"""
from django.core.exceptions import ValidationError as DjangoValidationError
repos:
- repo: https://github.com/browniebroke/django-codemod
# django-codemod is a tool to automatically
# fix Django deprecations.
# Any tag/version (>=1.10.2):
# https://github.com/browniebroke/django-codemod/tags
#
# Automatic execution of this hook has been disabled
# because it is a bit slow but its configuration is
# kept here so it can be easily run:
repos:
- repo: https://github.com/browniebroke/django-codemod
# django-codemod is a tool to automatically
# fix Django deprecations.
# Any tag/version (>=1.9.1):
# https://github.com/browniebroke/django-codemod/tags
#
# Automatic execution of this hook has been disabled
# because it is a bit slow but its configuration is
# kept here so it can be easily run:
@luzfcb
luzfcb / dismiss_all_twitter_topics.js
Last active March 8, 2022 09:47
Dismiss all twitter topics
// Dismiss all topics listed on https://twitter.com/YOUR_USERNAME/topics
// 1 - open the https://twitter.com/YOUR_USERNAME/topics
// 2 - open the browser console (Press Command + Option + J (Mac) or Control + Shift + J (Windows and Linux))
// 3 - copy this code
// 4 - paste the code on the console to run
// 5 - reload the page and run step 4 and 5 again until you no longer see "Dismiss" messages
.DEFAULT_GOAL := help
help: ## show help message
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m\033[0m\n"} /^[$$()% a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
compile: ## Compile foobar
@echo "##### Compiling foobar"