Skip to content

Instantly share code, notes, and snippets.

Avatar

Ondřej Caletka oskar456

View GitHub Profile
@oskar456
oskar456 / wgcf.py
Last active Nov 24, 2020
Cloudflare WARP linux client (using wg-quick for actual tunnel setup)
View wgcf.py
#!/usr/bin/env python3
import subprocess
import json
import os
from pathlib import Path
import requests
from requests.compat import urljoin
@oskar456
oskar456 / data.yaml
Last active Oct 18, 2020
Ansible bug with datetime in data
View data.yaml
---
data_1:
- id: 1
key: hello
- id: 2
key: world
data_2:
- id: 1
@oskar456
oskar456 / bh1750.py
Created Jun 20, 2015
BH1750 python library
View bh1750.py
#!/usr/bin/python2
# vim: expandtab ts=4 sw=4
# Inspired by http://www.raspberrypi-spy.co.uk/2015/03/bh1750fvi-i2c-digital-light-intensity-sensor/
import smbus
import time
class BH1750():
""" Implement BH1750 communication. """
@oskar456
oskar456 / wgwatchdog.sh
Last active Aug 22, 2020
Wireguard tunnel watchdog for OpenWRT
View wgwatchdog.sh
#!/bin/sh
check_reachability() {
local target="$1"
local retval
ping6 -c1 -W1 "$target" >/dev/null 2>&1
retval="$?"
[ "$retval" -eq 2 ] && {
ping -c1 -W1 "$target" >/dev/null 2>&1
retval="$?"
@oskar456
oskar456 / oneshot_setup.sh
Created Jul 5, 2020
Raspberry Pi Zero USB gadget mode with ethernet and serial
View oneshot_setup.sh
#!/bin/sh
# Enable gadget mode
echo "dtoverlay=dwc2,dr_mode=peripheral" >> /boot/config.txt
systemctl enable setupgadget.service
# alternatively: ln -s /etc/systemd/system/setupgadget.service /etc/systemd/system/basic.target.wants/setupgadget.service
# Enable getty on the virtual serial line
systemctl enable serial-getty@ttyGS0.service
# alternatively: ln -s /lib/systemd/system/serial-getty@.service /etc/systemd/system/getty.target.wants/serial-getty@ttyGS0.service
@oskar456
oskar456 / videocuttter.sh
Created Jul 2, 2020
Cut a video out of a long recording with fade in and out and volume normalization
View videocuttter.sh
#!/bin/bash
INFILE="input_video.mp4"
FPS=30
get_seconds() {
local seconds=0
IFS=":" read -ra T <<< "$1"
for x in "${T[@]}"; do
seconds=$(echo "$seconds * 60 + $x" | bc)
@oskar456
oskar456 / prouting.sh
Last active May 14, 2020
A simple script to set up policy routing on linux. It's stateless and detects everything automatically, so all you have to do is to run it after every network subsystem change. I run it in postup and postdown hooks in Gentoo network configuration file.
View prouting.sh
#!/bin/bash
IP="/bin/ip"
function prepare_rt_table() {
local rttables=/etc/iproute2/rt_tables
local iface=$1
[[ "${iface}" = 'lo' ]] && return
if ! egrep -q "\s${iface}\s*"\$ $rttables; then
idx=$(wc -l <$rttables)
@oskar456
oskar456 / rpz_unbound.sh
Last active May 6, 2020
RPZ policy for unbound - transform RPZ zone into local zone statements
View rpz_unbound.sh
#!/bin/bash
RPZ_ZONE="rpz.cesnet.cz"
RPZ_SERVER="nsa.cesnet.cz"
OUTPUT_FILE="unbound_$RPZ_ZONE.conf"
function resolve_target() {
local domain="$1"
shift
@oskar456
oskar456 / happykaktus.py
Created Feb 24, 2020
Scrap mujkaktus.cz and send news to a Telegram channel
View happykaktus.py
#!/usr/bin/env python3
import lxml.html
import urllib.request
from pathlib import Path
import requests
telegram_bot_token = "FIXME"
telegram_group_name = "@kvetinac"
@oskar456
oskar456 / md4pass.sh
Created Oct 7, 2016
MSCHAPv2 hash generator one-liner
View md4pass.sh
python -c 'import getpass,hashlib; print(hashlib.new("md4",getpass.getpass().encode("utf-16le")).hexdigest())'
You can’t perform that action at this time.