Skip to content

Instantly share code, notes, and snippets.

View opicron's full-sized avatar

Robbert Langezaal opicron

View GitHub Profile
@opicron
opicron / tokenReplace.bat
Created April 15, 2024 09:53 — forked from richard087/tokenReplace.bat
Batch file to do a token replacement on a text file, in Windows.
@echo off
rem sourced from http://stackoverflow.com/questions/5273937/how-to-replace-substrings-in-windows-batch-file
setlocal enabledelayedexpansion
set INTEXTFILE=test.txt
set OUTTEXTFILE=test_out.txt
set SEARCHTEXT=bath
set REPLACETEXT=hello
set OUTPUTLINE=
for /f "tokens=1,* delims=¶" %%A in ( '"type %INTEXTFILE%"') do (
@opicron
opicron / docker-iptables-fix.sh
Created October 20, 2022 10:41 — forked from pedrolamas/docker-iptables-fix.sh
Script to fix Docker iptables on Synology NAS
#!/bin/bash
currentAttempt=0
totalAttempts=10
delay=15
while [ $currentAttempt -lt $totalAttempts ]
do
currentAttempt=$(( $currentAttempt + 1 ))
echo "Attempt $currentAttempt of $totalAttempts..."
@opicron
opicron / self-update-script.py
Last active October 20, 2022 10:41 — forked from gesquive/self-update-script.py
python self update #python
def update(dl_url, force_update=False):
"""
Attempts to download the update url in order to find if an update is needed.
If an update is needed, the current script is backed up and the update is
saved in its place.
"""
import urllib
import re
from subprocess import call
def compare_versions(vA, vB):
// Allow partial regex pattern matches to be considered in SearchWP.
add_filter( 'searchwp\tokens\regex_patterns\only_full_matches', '__return_false' );
// Enable regex pattern match tokenization in SearchWP.
add_filter( 'searchwp\tokens\tokenize_pattern_matches', '__return_true' );
// Tell SearchWP to use a wildcard prefix when performing partial match logic.
add_filter( 'searchwp\query\partial_matches\wildcard_before', '__return_false' );
// Tell SearchWP not to use a wildcard prefix when performing partial match logic.
@opicron
opicron / gist:753431f617d657bd6a465d857dac11fd
Created January 26, 2022 10:08
SearchWP v4 - workaround
// Add WooCommerce Product (and Variation) SKUs to SearchWP.
// @link https://searchwp.com/documentation/knowledge-base/search-woocommerce-skus-and-variation-skus/
add_filter( 'searchwp\entry\data', function( $data, \SearchWP\Entry $entry ) {
// If this is not a Product, there's nothing to do.
if ( 'product' !== get_post_type( $entry->get_id() ) ) {
return $data;
}
$my_extra_meta_key = 'searchwp_skus';
// Reduce SearchWP's minimum character length to 2 (default is 3).
add_filter( 'searchwp\tokens\minimum_length', function( $min ) {
return 2;
} );
/*--------------------*/
/* support for parent/child products*/
/* -------------------*/
add_filter( 'searchwp\query\tokens', function( $terms, $query ){
$exact_match = get_posts( array(
@opicron
opicron / scrape.js
Last active October 20, 2022 10:34
scrape #js
module.exports = async ({ page }) => {
await page.setRequestInterception(true);
page.on('request', (req) => {
if(req.resourceType() === 'image' ){
req.abort();
}
else {
req.continue();
@opicron
opicron / vat.php
Last active October 20, 2022 10:35
Tax - exempt guests and customers #php #woocommerce
<?php
/**
* Function that will check for user role and turn off VAT/tax for that role
*/
function wc_diff_rate_for_user() {
// check for the user role
if ( ! is_user_logged_in() || current_user_can( 'customer' ) ) {
@opicron
opicron / dropship.php
Last active October 20, 2022 10:36
Add dropshipment costs #php #woocommerce
<?php
add_filter( 'woocommerce_package_rates', 'custom_shipping_costs', 20, 2 );
function custom_shipping_costs( $rates, $package )
{
// New shipping cost (can be calculated)
$new_cost = 5;
$tax_rate = 0.21;
global $woocommerce;
@opicron
opicron / functions.php
Last active October 20, 2022 10:36
facetwp custom pagination #php #facetwp
add_filter( 'facetwp_pager_html', function( $output, $params ) {
// show all pages
/*
$output = '';
if ( 1 < $params['total_pages'] ) {
for ( $i = 1; $i <= $params['total_pages']; $i++ ) {
$is_curr = ( $i === $params['page'] ) ? ' active' : '';
$output .= '<a class="facetwp-page' . $is_curr . '" data-page="' . $i . '">' . $i . '</a>';