Skip to content

Instantly share code, notes, and snippets.

@oskar456
oskar456 / wgcf.py
Last active Mar 31, 2021
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 / 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 / atlas_claimer.sh
Last active Mar 4, 2021
Claim 1,000,000 RIPE Atlas credits every time you can
View atlas_claimer.sh
#!/bin/bash
# Dependencies: curl, jq, realpath, date (GNU), at
API_KEY="FIXME"
claim_endpoint() {
local regid=$1
curl -s -H "Content-Type: application/json" \
-H "Accept: application/json" \
@oskar456
oskar456 / isholiday.py
Created Jun 29, 2016
Czech public holiday checker
View isholiday.py
#!/usr/bin/env python3
import datetime
def getholidays(year):
"""Return a set public holidays in CZ as (day, month) tuples."""
holidays = {
(1, 1), #Novy rok
(1, 5), #Svatek prace
(8, 5), #Den vitezstvi
@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 / 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