Skip to content

Instantly share code, notes, and snippets.

@ethaniel
ethaniel / relative_to_absolute.php
Created November 26, 2021 03:35
PHP script for converting relative humidity to absolute humidity
<?php
// formulas courtesy of https://planetcalc.com/2167/
$pressure = 1000; // Pressure in hPa
$temperature = 25; // Temperature in Celsius
$humidity = 75; // Relative Humidity in %
$e = 2.71828;
$tp = ($pressure * 133.322)/100;
@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
@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 / 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 / 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 / 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 / gstreamer_rtsp_to_shm.md
Last active March 1, 2024 00:49
Split one RTSP stream into multiple gstreamer pipelines
  1. Get RTSP video, decode it, apply framerate and send to shared buffer. Don't forget to set shm-size to something high, because you're now dealing with decoded raw video:

gst-launch-1.0 -v rtspsrc location="rtsp://192.168.86.249/live/sala" protocols=tcp latency=1000 ! watchdog timeout=10000 ! rtph264depay ! h264parse ! avdec_h264 ! videorate ! video/x-raw,framerate=30/1 ! shmsink wait-for-connection=false socket-path=/tmp/foo shm-size=100000000

  1. Note the caps in the output:

/GstPipeline:pipeline0/GstShmSink:shmsink0.GstPad:sink: caps = video/x-raw, format=(string)I420, width=(int)2560, height=(int)1440, interlace-mode=(string)progressive, pixel-aspect-ratio=(fraction)1/1, chroma-site=(string)mpeg2, colorimetry=(string)1:0:0:0, framerate=(fraction)30/1

  1. Read decoded video from shared buffer (input the width,height,format,framerate caps from above):
@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 / 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 / ceph_deep_scrub.php
Last active March 5, 2024 22:56
This script controls Ceph deep scrubs, making sure that each OSD is busy with a deep scrub.
<?php
/*
Script to always have 1 deep scrub running per OSD.
## About
1. Helps with the following error: PG_NOT_DEEP_SCRUBBED HEALTH_WARN (N pgs not deep-scrubbed in time)
2. Doesn't run scrubbing on PGs that were deep scrubbed less than 2 weeks ago, releasing