Skip to content

Instantly share code, notes, and snippets.

@luminoso
luminoso / koalas.py
Created March 11, 2020 22:02
koalas itertuples wrapper for iterrows
# koalas don't support iterrows. so we convert iterrows() to itertuples() format
if internal_itertuples:
Row = namedtuple('Row', df.columns)
def convert_iterrow_to_itertuples(df):
for row in df.iterrows():
yield Row(*row[1])
itertuples = convert_iterrow_to_itertuples(df)
else:
@luminoso
luminoso / netns.txt
Created February 17, 2020 22:54
running an OpenVPN tunnel inside a network namespace
Linux network namespaces can be used to control which processes should be tunneled by OpenVPN.
http://www.naju.se/articles/openvpn-netns.html
Example
First create an --up and --down script for OpenVPN. This script will create the VPN tunnel interface inside a network namespace called vpn, instead of the default namespace.
cat > netns-script << 'EOF'
#!/bin/sh
case $script_type in
up)
@luminoso
luminoso / clevis.sh
Last active July 15, 2023 08:58
fedora base install minimal setup
# https://wiki.archlinux.org/title/Trusted_Platform_Module#Clevis
sudo dnf install clevis\*
# check the correct partition with lsbk
sudo lsblk
# bind clevis to secure boot
sudo clevis luks bind -d /dev/nvme0n1p3 tpm2 '{"pcr_ids":"1,7"}'
@luminoso
luminoso / openwrt_addons.sh
Last active April 17, 2022 07:02
openwrt base addons
opkg update
# luci addons
opkg install luci-app-statistics
# dns over tls
# https://openwrt.org/docs/guide-user/services/dns/dot_dnsmasq_stubby
opkg install dnsmasq stubby
# generic routing encapsulation. requirement for vpn.ua.pt
@luminoso
luminoso / jupyter.sh
Last active August 1, 2023 13:55
base install jupyerlab datascience project
# CONDA
# create env
conda config --add channels conda-forge
conda config --set channel_priority strict
conda create --strict-channel-priority -n jupyter
conda activate jupyter
# jupyter, notebook and old notebook extensions
conda install -y jupyterlab
@luminoso
luminoso / logger.py
Created February 4, 2020 16:06
python double file and console logger different levels
import logging
filename = 'spam.log'
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
# create file handler which logs even debug messages
fh = logging.FileHandler(filename)
fh.setLevel(logging.DEBUG)
@luminoso
luminoso / .screenrc
Last active January 30, 2020 21:28
screen config .screenrc status bar time host window list
vbell off
term screen-256color
hardstatus off
hardstatus alwayslastline
hardstatus alwayslastline '%{= G}[ %{G}%H %{g}][%= %{= w}%?%-Lw%?%{= R}%n*%f %t%?%{= R}(%u)%?%{= w}%+Lw%?%= %{= g}][ %{y}Load: %l %{g}][%{B}%Y-%m-%d %{W}%c:%s %{g}]'
defnonblock on
scrollback 15000
setenv LD_PRELOAD /usr/lib/libjemalloc.so
@luminoso
luminoso / logging.py
Created January 22, 2020 18:11
python logging init
import logging
# level=logging._nameToLevel[verbosity_level]
# level=logging.DEBUG
# format="%(asctime)s [%(module)-12.12s] [%(levelname)-5.5s] %(message)s",
logging.basicConfig(
level=logging.DEBUG,
format="%(asctime)s [%(levelname)-5.5s] %(message)s",
@luminoso
luminoso / test_pytorch_cuda.py
Created January 22, 2020 10:20
test CUDA avaialbility pytorch
# tests the avalability of cuda for pytorch
import torch
torch.cuda.current_device()
torch.cuda.device(0)
torch.cuda.device_count()
torch.cuda.get_device_name(0)
torch.cuda.is_available()
@luminoso
luminoso / ijulia.jl
Created January 22, 2020 09:36
add IJulia CentOS 7.x ZMQ ABI GLIBCXX
# trick to make iJulia work on CentOS 7
# CentOS looks like to have some kind of ABI incompatibility
# ERROR: LoadError: InitError: could not load library "/home/centos/.julia/artifacts/8b67c92bc6eb60d96d3488bf4b48bd3a38f70c53/lib/libzmq.so"
# /usr/bin/../lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by /home/centos/.julia/artifacts/8b67c92bc6eb60d96d3488bf4b48bd3a38f70c53/lib/libzmq.so)
]
add ZMQ@1.1.0
add iJulia
using iJulia