Skip to content

Instantly share code, notes, and snippets.

@ethaniel
ethaniel / readme.md
Created May 20, 2024 17:38
Batch update resource timeouts in pacemaker

I needed to batch update the monitor and stop timeouts in all of my pacemaker resources. I didn't want to rely on the default values, so I wrote this oneliner:

pcs resource | awk '{print $2}' | while read RESOURCE; do pcs resource update $RESOURCE op start timeout=20s op stop timeout=200s op monitor interval=10s timeout=200s; done
@ethaniel
ethaniel / readme.md
Last active April 25, 2024 16:23
How to setup a Nordvpn client inside a docker container, running on a Raspberry Pi, and then route some computers on the local network through it

Intro

I live in Thailand. Sometimes my internet connection is slow, because my ISP has poor international connectivity with some destinations (Europe, for instance). Sometimes routes that the ISP chooses have a lot of packet losses, or just slow. I needed a way to route SOME of the devices on my LAN another way. I decided to use NordVPN because they have a lot of servers worldwide and my ISP provides a reliable route to SOME of them (I use docker run -it trishmapow/nordvpn-tools FR --load 30 --fping | awk '{ print $NF,$0 }' | sort -k1,1 -n | cut -f2- -d' ' | head -n 10 to find the best servers with the lowest ping for instance). However, I didn't want to deal with installing a VPN client on every device, so I decided to make one inside my Raspberry (but without having the Raspberry use the VPN connection itself, because I have other services running on it).

You will need

  1. Raspberry Pi wired by LAN cable
  2. Through raspi-config go to Advanced options - Network Interface Names - choose No to
@ethaniel
ethaniel / hikvision.php
Created March 1, 2024 18:40
Simple PHP script to connect to Hikvision notification API
<?php
// Composer dependencies:
// composer require amphp/socket amphp/byte-stream
// IMPORTANT: Go to System > Security -> Authentication tab, set "WEB Authentication" to "digest/basic" first!!!
// Otherwise you will get authentication errors
require __DIR__ . '/vendor/autoload.php';
@ethaniel
ethaniel / ftp_server.php
Last active March 1, 2024 12:46
Simple FTP Server written in PHP to receive images from Hikvision cameras
<?php
require __DIR__ . '/vendor/autoload.php';
use Amp\Loop;
use Amp\Socket\Socket;
use function Amp\asyncCall;
$port1 = 1021; // Primary FTP port (you list it in Hikvision), it receives FTP commands
$port2 = 1022; // Secondary FTP port (for receiving binary data - images)
@ethaniel
ethaniel / remove_icc.php
Created January 31, 2024 13:39
Solution for: icc_transform error. Message: libvips error: icc_transform: no output profile
<?php
// If you are using PHP Imagine, then you can catch the "icc_transform error. Message: libvips error: icc_transform: no output profile" error
// Then you need to remove the icc-profile-data and repeat the call
try {
$img = $img->thumbnail($box, Imagine\Image\ImageInterface::THUMBNAIL_OUTBOUND);
} catch (\Exception $e) {
if (strstr($e->getMessage(), "icc")) {
$img->getVips()->remove('icc-profile-data');
@ethaniel
ethaniel / delete.js
Last active January 11, 2024 08:12
Batch/bulk delete Cloudflare DNS records without API
// Copy-paste this into your browser's console.
// WARNING: This will delete ALL DNS RECORDS that are visible on the current page one by one.
// It might take 5-10 seconds to delete one DNS record.
// Based on https://community.cloudflare.com/t/useful-script-to-bulk-delete-all-incorrectly-imported-dns-records/131144
// Valid for 11 January 2024. Might need to be redone later.
(() => {
const deleteTopRecord = () => {
if (document.querySelector('[data-testid="dns-delete-modal-confirm-button"]')) {
@ethaniel
ethaniel / readme.md
Last active March 26, 2024 18:14
Hikvision NVR updates camera settings (SVC, Framerate) automatically.

If you don't want this, then enable ONVIF on every camera in the settings (add a new ONVIF user with the privilege "Media operator"), and then change the protocol to ONVIF on the NVR side.

@ethaniel
ethaniel / readme.md
Last active February 4, 2023 18:47
Grafana: Highlight 12 hour intervals in graphs for easier viewing
  1. Open Grafana dashboard settings.
  2. Go to "Annotations"
  3. Create an annotation with a data source "InfluxDB" and add the following query:
import "array"
import "timezone"
import "date"

option location = timezone.location(name: "Asia/Bangkok")
@ethaniel
ethaniel / min_teamviewer.ahk
Last active October 19, 2022 13:33
AutoHotKey script to minimize the TeamViewer side panel when I connect to a computer
; Save this file somewhere (I keep it on my desktop) as min_teamviewer.ahk and run it once
; It will create a shortcut in the Startup folder, so it will be loaded automatically on system reboot
#SingleInstance Force
;LWin::
;RWin::
DetectHiddenText, on
@ethaniel
ethaniel / asterisk_problems.md
Last active August 27, 2022 07:58
asterisk: symbol lookup error: /lib/libasteriskssl.so.1: undefined symbol: ast_register_file_version

Recently, I've been upgrading manually compiled Asterisk on my Centos to a version coming from Tucny's Repo. When starting up the Asterisk, I've noticed the following error:

asterisk: symbol lookup error: /lib/libasteriskssl.so.1: undefined symbol: ast_register_file_version

The problem came from leftover files from the manual build. Here is how I fixed this:

rm -rfv /lib/libasterisk*
rm -rfv /usr/lib/asterisk