Skip to content

Instantly share code, notes, and snippets.

View kasparsd's full-sized avatar

Kaspars Dambis kasparsd

View GitHub Profile
@kasparsd
kasparsd / fix-ssl-please.php
Created March 8, 2024 14:06
Fix SSL (HTTPs) URLs in WP content
<?php
/*
Plugin Name: Fix SSL Please
Plugin URI: https://github.com/kasparsd/ssl-fix
GitHub URI: https://github.com/kasparsd/ssl-fix
Description: Ensure that everything works over SSL
Version: 0.1.1
Author: Kaspars Dambis
Author URI: http://kaspars.net
*/
@kasparsd
kasparsd / admin-pwa.php
Last active February 20, 2024 12:17
wp-admin-pwa.php
<?php
/**
* Plugin Name: Admin PWA
*/
namespace Preseto\Admin_PWA;
const ACTION_QUERY_VAR = 'admin-pwa';
function manifest_url() {
@kasparsd
kasparsd / zip-chunks.php
Last active January 16, 2024 09:10
Zip chunks with PHP (split ZIP with max size)
<?php // Run as `php zip-chunks.php path/to/directory`.
$chunk_limit = 1024 * 1024 * 1024; // 1 GB
function get_files( $path ) {
$files = glob( rtrim( $path, '\\/' ) . '/*' );
foreach ( $files as $file ) {
if ( is_dir( $file ) ) {
$files = array_merge( $files, get_files( $file ) );
}
<?xml version="1.0" encoding="UTF-8" ?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:soapenc="http://www.w3.org/2003/05/soap-encoding"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:tt="http://www.onvif.org/ver10/schema" xmlns:tds="http://www.onvif.org/ver10/device/wsdl"
xmlns:trt="http://www.onvif.org/ver10/media/wsdl" xmlns:timg="http://www.onvif.org/ver20/imaging/wsdl"
xmlns:tev="http://www.onvif.org/ver10/events/wsdl" xmlns:tptz="http://www.onvif.org/ver20/ptz/wsdl"
xmlns:tan="http://www.onvif.org/ver20/analytics/wsdl" xmlns:tst="http://www.onvif.org/ver10/storage/wsdl"
xmlns:ter="http://www.onvif.org/ver10/error" xmlns:dn="http://www.onvif.org/ver10/network/wsdl"
xmlns:tns1="http://www.onvif.org/ver10/topics" xmlns:tmd="http://www.onvif.org/ver10/deviceIO/wsdl"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl" xmlns:wsoap12="http://schemas.xmlsoap.org/wsdl/soap12"
<?php
function list_to_file( $list, $file ) {
array_unshift( $list, array_keys( reset( $list ) ) ); // Append the keys to the top of the file.
$csv_file = fopen( $file, 'w' );
foreach ( $list as $fields ) {
fputcsv( $csv_file, $fields );
}
@kasparsd
kasparsd / configuration.yml
Created April 22, 2022 14:49
Degree day sensor for Home Assistant
sensor:
- platform: template
sensors:
t81_temperature:
friendly_name: "Outside Temperature"
unit_of_measurement: '°C'
value_template: "{{ state_attr('weather.t81', 'temperature') }}"
t81_humidity:
@kasparsd
kasparsd / disable-custom-sidebars-context.php
Created February 25, 2022 15:33
Remove the Custom Sidebars plugin override logic for widget output
<?php
// Remove the Custom Sidebars plugin override logic for widget output.
add_action(
'plugins_loaded',
function() {
if ( class_exists( 'CustomSidebarsVisibility' ) ) {
remove_filter(
'sidebars_widgets',
array( CustomSidebarsVisibility::instance(), 'sidebars_widgets' )
@kasparsd
kasparsd / app_upgrade.sh
Last active July 12, 2022 23:34
Zemismart Zigbee Gateway TYZS4, see https://paulbanks.org/projects/lidl-zigbee/
#!/bin/sh
#########################################
#Function: update tuya_gateway app
#Usage: ./app_upgrade.sh
#Author: hxh
#Company: tuya
#Version: 3.0
#########################################
ENG_MODE_FILE=/tmp/eng_mode
@kasparsd
kasparsd / uptime.sh
Last active February 9, 2021 18:10
Basic uptime monitor
#!/bin/bash
NOTIFY_FROM="no-reply@example.com"
NOTIFY_TO="hi@example.com"
URLS=(
"https://example.com"
"https://google.com"
)
<?php
/**
* Map all categories to the new category tree.
*
* - Create a list of new categories by their path of slugs.
*/
class Terms {
/**