Skip to content

Instantly share code, notes, and snippets.

View ZsBT's full-sized avatar
💭
💙 💛

ZS ZsBT

💭
💙 💛
View GitHub Profile
@ZsBT
ZsBT / __init__.py
Created November 30, 2022 19:39
ha w1k init
"""
Support for W1000 energy portal
Thanks to https://github.com/amargo/ for the login session ideas
"""
import logging
import aiohttp
import voluptuous as vol
@ZsBT
ZsBT / ip_in_subnet.lua
Created August 27, 2021 15:08
check if an IP is a member of a subnet.
-- I only found overcomplicated solutions for this small problem so I wrote this for myself.
-- github.com/ZsBT
-- convert IP string to long integer
local function ip2long( ip )
if not ip then return false end
local o1,o2,o3,o4=ip:match("^(%d%d?%d?)%.(%d%d?%d?)%.(%d%d?%d?)%.(%d%d?%d?)$")
if not o1 or not o2 or not o3 or not o4 then return false end
return tonumber(o4) + (tonumber(o3) << 8) + (tonumber(o2) << 16) + (tonumber(o1) << 24)
@ZsBT
ZsBT / NBIS.Dockerfile
Created March 8, 2020 13:09
NBIS software build
FROM debian:stable-slim
WORKDIR /usr/src
RUN apt update && apt -y install wget unzip gcc make build-essential
RUN wget https://nigos.nist.gov/nist/nbis/nbis_v5_0_0.zip && unzip *zip
RUN apt -y install cmake
RUN cd Rel_* && ./setup.sh /opt --without-X11 --64 && make config && make it && make install LIBNBIS=yes
RUN find /opt -type f
@ZsBT
ZsBT / install-dc.sh
Created January 18, 2020 08:07
install docker&compose packages on Debian
#!/bin/sh
sudo apt -y install apt-transport-https ca-certificates curl gnupg2 software-properties-common
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
sudo add-apt-repository -y \
"deb [arch=amd64] https://download.docker.com/linux/debian \
$(lsb_release -cs) \
stable"
@ZsBT
ZsBT / scrubtrfs.sh
Last active July 31, 2019 11:36
btrfs maintenance shell - functions only
#!/bin/bash
#
# BTRFS maintenance
# scrub or balance all btrfs fs present on system
#
scrub() {
for device in $(mount -t btrfs | cut -d ' ' -f 1 |sort -u) ;do
echo "scrub $device"
btrfs scrub start -B -c 3 -n 9 -d $device || exit 1
@ZsBT
ZsBT / hactl.sh
Last active June 9, 2022 00:27
socket control script for HAproxy backends
#!/bin/bash
#
# control script for HAproxy backends.
#
# rare usage does not allow me to remember socket commands...
# @author ZsBT@GitHub
#
_socmd(){ echo "$*" | socat stdio $(egrep -o '[^ ]+\.sock' /etc/haproxy/haproxy.cfg); }
[ -z "$(which socat)" ] && { echo "error: socat not installed";exit 1; }
@ZsBT
ZsBT / mosquitto.conf
Last active May 3, 2018 19:50
mosquitto SSL server using Letsencrypt certificate
listener 1883 localhost
listener 2883
certfile /etc/letsencrypt/live/my.example.com/cert.pem
cafile /etc/letsencrypt/live/my.example.com/chain.pem
keyfile /etc/letsencrypt/live/my.example.com/privkey.pem
@ZsBT
ZsBT / db-size.pg.sql
Last active June 9, 2022 00:27
show occupied space in a postgresql database
create view v_sizeof_dbs as
select datname dbname
,pg_size_pretty(pg_database_size(datname)) hsize
from pg_database
order by pg_database_size(datname) desc;
create view v_sizeof_tables as
SELECT table_catalog,table_schema,table_name
,pg_size_pretty(pg_table_size(table_schema||'.'||table_name)) table_hsize
FROM information_schema.tables
@ZsBT
ZsBT / systemd.service
Last active January 23, 2018 06:51
systemd unit cheatsheet
[Unit]
Description = fotók betöltése
After=postgresql.service
Requires=postgresql.service
Wants=postgresql.service
[Service]
ExecStart = /home/szerver/foto-devtolt.py
ExecReload = /bin/kill -HUP $MAINPID
@ZsBT
ZsBT / setup-mysql-replication.sh
Last active November 28, 2022 07:30
create mysql/mariadb master-master replication
#!/bin/bash
#
# setup mysql replication.
# run this script parallel on both servers as we need log file name and position on the other node
#
#
ROOT_PASS="rootP@ssw0rd"
REPLI_PASS="replicationP@ssw0rd"
SIBLING_IP="1.2.3.4"