Skip to content

Instantly share code, notes, and snippets.

View mikaelz's full-sized avatar

Michal Zuber mikaelz

View GitHub Profile
# Basic commands
:Git [args] # does what you'd expect
all of your `~/.gitconfig` aliases are available.
:Git! [args] # same as before, dumping output to a tmp file
Moving inside a repo.
@mikaelz
mikaelz / htaccess
Created August 25, 2015 11:29
htaccess for WordPress on localhost in subfolder with uploads redirect match to fetch uploads from internet
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /example/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /example/index.php [L]
# Fetch uploads from public URL
@mikaelz
mikaelz / delete-all-woocommerce-products.php
Last active March 15, 2024 12:53
Remove all WooCommerce products from database via SQL
<?php
require dirname(__FILE__).'/wp-blog-header.php';
$wpdb->query("DELETE FROM wp_terms WHERE term_id IN (SELECT term_id FROM wp_term_taxonomy WHERE taxonomy LIKE 'pa_%')");
$wpdb->query("DELETE FROM wp_term_taxonomy WHERE taxonomy LIKE 'pa_%'");
$wpdb->query("DELETE FROM wp_term_relationships WHERE term_taxonomy_id not IN (SELECT term_taxonomy_id FROM wp_term_taxonomy)");
$wpdb->query("DELETE FROM wp_term_relationships WHERE object_id IN (SELECT ID FROM wp_posts WHERE post_type IN ('product','product_variation'))");
$wpdb->query("DELETE FROM wp_postmeta WHERE post_id IN (SELECT ID FROM wp_posts WHERE post_type IN ('product','product_variation'))");
$wpdb->query("DELETE FROM wp_posts WHERE post_type IN ('product','product_variation')");
#!/bin/bash
ffmpeg -rtsp_transport tcp \
-i rtsp://smartiptv:PASSWORD@192.168.2.3/Streaming/Channels/102 \
-i rtsp://smartiptv:PASSWORD@192.168.2.3/Streaming/Channels/202 \
-i rtsp://smartiptv:PASSWORD@192.168.2.3/Streaming/Channels/302 \
-i rtsp://smartiptv:PASSWORD@192.168.2.3/Streaming/Channels/402 \
-i rtsp://smartiptv:PASSWORD@192.168.2.3/Streaming/Channels/502 \
-i rtsp://smartiptv:PASSWORD@192.168.2.3/Streaming/Channels/602 \
-filter_complex "
@mikaelz
mikaelz / YahooFinance.js
Created April 20, 2020 06:34
Google script to fetch stock quote data from Yahoo Finance
function YahooFinance(ticker) {
var ticker = ticker || "GOOG";
ticker = encodeURI(ticker);
var response = UrlFetchApp.fetch("https://query2.finance.yahoo.com/v7/finance/options/" + ticker);
var chain = JSON.parse(response.getContentText());
return parseFloat(chain.optionChain.result[0].quote.regularMarketPrice);
}
@mikaelz
mikaelz / remove-all-product-categories-tags.php
Created January 27, 2016 11:37
Remove all WooCommerce product categories and tags
<?php
require dirname(__FILE__).'/wp-blog-header.php';
$wpdb->query("DELETE a,c FROM wp_terms AS a
LEFT JOIN wp_term_taxonomy AS c ON a.term_id = c.term_id
LEFT JOIN wp_term_relationships AS b ON b.term_taxonomy_id = c.term_taxonomy_id
WHERE c.taxonomy = 'product_tag'");
$wpdb->query("DELETE a,c FROM wp_terms AS a
LEFT JOIN wp_term_taxonomy AS c ON a.term_id = c.term_id
<?php
declare(strict_types=1);
namespace App\Infrastructure\Serializer;
use Symfony\Component\Serializer\Encoder\DecoderInterface;
use Symfony\Component\Serializer\Encoder\EncoderInterface;
class FormEncoder implements EncoderInterface, DecoderInterface
@mikaelz
mikaelz / wp-login-download-pdf.sh
Created May 20, 2023 09:58
Wget PDF files after logging into WordPress
#!/bin/bash
# Login
wget --user-agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3" \
--save-cookies cookies.txt --keep-session-cookies --no-check-certificate --delete-after \
--post-data="log=REPLACE_WITH_LOGIN&pwd=REPLACE_WITH_PASS&testcookie=1" https://example.com/wp-login.php
# Download PDFs
wget --mirror --load-cookies cookies.txt --keep-session-cookies --no-check-certificate \
--random-wait -e robots=off -A.pdf --page-requisites --adjust-extension --convert-links --backup-converted --no-parent \
#!/bin/bash
cd /tmp
echo "Wget $1"
wget --spider --recursive --level=3 --no-verbose --output-file=sitemap.txt $1
echo "Grep URLs"
grep -i URL /tmp/sitemap.txt | awk -F 'URL:' '{print $2}' | awk '{$1=$1};1' | awk '{print $1}' | sort -u | sed '/^$/d' > /tmp/sitemap-urls.txt
header='<?xml version="1.0" encoding="UTF-8"?><urlset
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
@mikaelz
mikaelz / get_time_from_ntp.php
Created September 17, 2018 10:54 — forked from bohwaz/get_time_from_ntp.php
Fetches timestamp from a NTP server in PHP
<?php
/**
* Returns UNIX timestamp from a NTP server (RFC 5905)
*
* @param string $host Server host (default is pool.ntp.org)
* @param integer $timeout Timeout in seconds (default is 10 seconds)
* @return integer Number of seconds since January 1st 1970
*/
function getTimeFromNTP($host = 'pool.ntp.org', $timeout = 10)