Skip to content

Instantly share code, notes, and snippets.

@kidpixo
kidpixo / python_version_checker.py
Last active June 27, 2022 08:20
Pyhton function to check installed packages version from shell. Pure python, no requirements. Now with CLI colors!
#!/usr/bin/env python
"""Pyhton function to check installed packages version from shell. Pure python, no requirements.
"""
# define CLI colors
RED = '\033[31m' # mode 31 = red forground
GREEN = '\033[1;32m' # mode 32 = green forground
CYAN = '\033[34m' # mode 32 = green forground
RESET = '\033[0m' # mode 0 = reset
@kidpixo
kidpixo / .gitignore
Last active November 24, 2021 13:20
Read binary data from Lunar Prospector Reduced Spectrometer Data Special Products (how to read binary data from [PDS Geosciences Node Data and Services)
data/
# Created by https://www.toptal.com/developers/gitignore/api/python
# Edit at https://www.toptal.com/developers/gitignore?templates=python
### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
@kidpixo
kidpixo / config
Last active November 19, 2021 14:19
blocklet for i3blocks : get current CPU frequency from lscpu, extract the max/min and convert to GHz. Pure python, no requirments.
[cpu-freq]
interval=5
# standard color scale. MUST BE 4 VALUES.
# COLORS_FREQ='#85cc00,#b58900,#cb4b16,#dc322f'
# in MHz, if set Min/Max are not used. MUST BE 3 VALUES.
# FREQUENCIES='1500,2300,3100'
# Freq max/min MHz
# MIN_FREQ=1400
# MAX_FREQ=4100
# number of frequency intervals for color
@kidpixo
kidpixo / output.png
Last active October 22, 2021 13:00
Interpolate a Pandas.DataFrame to an input index, drop duplicated index, with scipy.interpolate methods.
output.png
@kidpixo
kidpixo / django_init
Last active October 19, 2021 09:46 — forked from kalafut/django_init
Simple creation of a single-app django project
#!/bin/bash
#
# Simple creation of a single-app django project, as described in: https://zindilis.com/posts/django-anatomy-for-single-app/
#
# ./django_init foo
#
# This will result is the following flat structure:
#
# .
# └── foo
#------------------------------------------------
# Name : yt-streamer
# Input : youtube URL
# Purpose : stream url video to mpv. see:
# https://github.com/ytdl-org/youtube-dl/issues/2124#issuecomment-32429104
#------------------------------------------------
yt-streamer() {
# locale colors do not work in sub-functions
open=$'\001'
close=$'\002'
#!/usr/bin/env python
"""Show table content with rich. Quick'n'dirty: no validity checks, only the fun :-D.
"""
import sys
from pandas import read_csv
from rich import print
from pathlib import Path
import os
size = os.get_terminal_size()
for p in sys.argv[1:]:
@kidpixo
kidpixo / example_output.png
Last active April 13, 2023 13:35
Pyhton function to check installed packages version from shell. This uses the shell default python, useful to check you local virtualenvs/conda envs.
example_output.png
# tested using https://github.com/uber/h3-py-notebooks/blob/master/notebooks/usage.ipynb
from h3 import h3
from shapely.geometry.polygon import Polygon
h3_list = [ Polygon(h3.h3_to_geo_boundary(he)) for he in h3.hex_ring(h,2)]
n = len(h3_list)
print(f'Polygon.exterior.is_closed = {h3_list[0].exterior.is_closed}')
import geopandas as gpd
@kidpixo
kidpixo / zathura_history_rofi.sh
Last active March 4, 2021 16:26
Open file from zathura history with rofi, checking if files exist. (Bash>=4.4 for array functions)
#!/bin/sh
# see https://unix.stackexchange.com/questions/467524/open-file-from-history-in-zathura
# save filepaths in history to array, reverse order
readarray -t Data < <(grep -o '/.*\.[[:alpha:]]\{,3\}' ~/.local/share/zathura/history | tac)
# loop and unset not existing files
for i in "${!Data[@]}"
do
if ! [ -e "${Data[$i]}" ]; then