Skip to content

Instantly share code, notes, and snippets.

@peci1
peci1 / check_raid_status.sh
Last active December 17, 2024 20:06
A script for Turris Omnia that checks the status of a JMicron JMS56x RAID controller and sends a notification if something's wrong.
#!/bin/bash
# Based on the script from https://forum.odroid.com/viewtopic.php?t=29298
# Changes to that script are released under BSD license (c) Martin Pecka, 2019.
# raidmgr_static can be downloaded here: https://wiki.odroid.com/_media/accessory/add-on_boards/xu4_cloudshell2/raidmgr_static_cloudshell2.zip
RAID_MANAGER="/usr/bin/raidmgr_static"
STATUS="$(echo -e "SR C0\nEX\n" | $RAID_MANAGER)"
@peci1
peci1 / revert_packages_to_ppa_versions.sh
Created January 7, 2019 12:54
Revert all packages from non-PPA versions to their latest PPA version.
#!/usr/bin/env bash
# BSD 3-clause license, copyright Martin Pecka @ 2019
# This script outputs a command that will revert all packages from non-PPA versions to their latest PPA version.
# This may be handy i.e. for finding packages for which you installed a newer version from a .deb file, or after
# incompletely removing a PPA.
export LC_ALL=C
update_deb_from_github() {
repo=$1 # will use github.com/repos/${repo}/releases, so set to e.g. BoostIO/boostnote
pkg=$2 # name of the Deiban package e.g. apt can use, so e.g. boostnote
deb_type=$3 # a substring of the deb file on github releases which uniquely tells the requested deb from other deb files on the latest releases page
version_installed=$(LANG=C aptitude show boostnote | grep Version | grep -o '[0-9]\{1,2\}\.[0-9]\{1,2\}\.[0-9]\{1,2\}')
download_link=$(curl -s https://api.github.com/repos/${repo}/releases/latest | jq -r ".assets[] | .browser_download_url" | grep "${deb_type}.*\.deb")
version_upstream=$(echo ${download_link} | grep -o '[0-9]\{1,2\}\.[0-9]\{1,2\}\.[0-9]\{1,2\}' | head -n1)
if [[ "${version_installed}" != "${version_upstream}" ]]; then
wget -O "/tmp/${pkg}.deb" "${download_link}"
@peci1
peci1 / scipy_odr_test.py
Created September 17, 2018 14:18
Test of scipy.odr regressor
from __future__ import print_function
import numpy as np
import scipy.linalg
from scipy.odr import *
import matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import pyplot as plt
import sys
import time
@peci1
peci1 / anonymize_pdf.sh
Last active January 4, 2021 18:07
Anonymize a PDF document with comments so that both document metadata and comment author data do not disclose who the author is.
qpdf --qdf --object-streams=disable $1 $1.tmp # uncompress /FlateDecode sections
perl -pe 's/(?<=\/T \()(.*?)(?=\))/ "x" x length($1) /e' $1.tmp > $1.tmp2 # remove /T commands containing author name in comments
qpdf --compress-streams=y $1.tmp2 $1.tmp3 # recompress streams
qpdf --empty --pages $1.tmp3 1-z -- $1.anonymous.pdf # remove document metadata (this also removes whole comments)
rm $1.tmp* # cleanup
@peci1
peci1 / pb_model_executor.py
Created June 1, 2018 20:25
Tensorflow executor of models from TF 1.4+ on TF 1.3- (python 3)
import tensorflow as tf
import numpy as np
class PbModelExecutor:
def __init__(self, model_path, input_shape, input_name='input', output_name='output:0'):
self.session = tf.Session()
self.input = tf.placeholder(tf.float32, shape=input_shape)
@peci1
peci1 / nas
Created May 31, 2018 00:01
OpenWRT: automount NTFS drive by UUID and before mountd comes into action and mounts it under /tmp/run/mountd
#!/bin/sh /etc/rc.common
# This is a procd initscript, so put it in /etc/init.d/
START=79 # Important: this number must be lower than the START number in /etc/init.d/mountd !!!
USE_PROCD=1
PROGNAME="/usr/bin/ntfs-3g"
# Fill these values as desired
@peci1
peci1 / print_bytes_in_all_encodings.py
Created December 25, 2017 23:05
Print the characters corresponding to the given byte sequence in all encodings known to the python interpreter.
#!/usr/bin/env python3
import encodings
import pkgutil
bytes_to_decode = b"\xc4\x9b"
codecs = []
for importer, modname, ispkg in pkgutil.iter_modules(encodings.__path__):
try:
@peci1
peci1 / torrc
Last active March 31, 2022 14:47
My torrc on Turris Omnia
SOCKSPort 9050
SOCKSPolicy accept 127.0.0.1/32
SOCKSPolicy accept 192.168.18.0/24
SOCKSPolicy accept6 FC00::/7
SOCKSPolicy reject *
Log notice syslog
RunAsDaemon 1
DataDirectory /srv/tor
AvoidDiskWrites 1
ORPort 9001
@peci1
peci1 / transparent-tor.diff
Created November 2, 2017 02:14
A trial to get transparent .onion translation on Omnia
diff -Nru @161/etc/config/resolver @/etc/config/resolver
--- @161/etc/config/resolver 2017-10-01 21:01:14.375423242 +0200
+++ @/etc/config/resolver 2017-11-02 01:13:47.862130135 +0100
@@ -21,6 +21,7 @@
option log_stderr '1'
option log_stdout '1'
option forks '1'
+ option include_config '/etc/kresd/config.conf'
config resolver 'unbound'