Skip to content

Instantly share code, notes, and snippets.

View tott's full-sized avatar

Thorsten Ott tott

  • Germany, Cologne area
View GitHub Profile
@tott
tott / read-backlight.py
Created November 22, 2018 11:41
Read backlight for x230 / x330 taobao FHD mod
#!/usr/bin/env python
import sys
import array
import usb.core
import usb.util
import os
path = "/tmp/backlight-value"
# decimal vendor and product values
@tott
tott / gist:a10bebe067d517455e423eb32f7d1d3d
Created October 16, 2018 21:59
Sending multipart mail with wp_mail (untested)
<?php
$to = "[email protected]";
$subject = "My Multipart test";
$message = "I am the plain text message";
$boundary = uniqid(rand(), true);
$header = "MIME-Version: 1.0\n"
@tott
tott / options-monitor.sh
Last active July 10, 2018 03:32
WordPress options table size Nagios monitor
#!/bin/bash
OPTIND=1
verbose=0
dbuser=""
dbpasswd=""
while getopts "vh?U:P:H:" opt; do
case "$opt" in
@tott
tott / minions-post-pusher.php
Last active April 24, 2019 16:39
WP-Minions ( https://github.com/tott/WP-Minions/tree/alter-job-data ) for multisite syndication to one site.
<?php
/**
* Plugin Name: WP Minions Post Pusher
* Description: Pushes all published posts to one blog using wp-minions
* Version: 1.0
* Author: Thorsten ott
* Author URI: http://thorsten-ott.de/
* License: GPLv2 or later
*/
#!/bin/bash
# ./curl-urls.sh numprocessses http://urltograp urlpattern
# ./curl-urls.sh 3 http://www.domain.com domain.com
numprocessses=$1
baseurl=$2
urlpattern=$3
function forky() {
local num_par_procs
if [[ -z $1 ]] ; then
@tott
tott / gist:a7638cb9b602425b3c87
Last active August 29, 2015 14:05
workaround disabling xmlrpc from within wordpress mu-plugins file
/**
* Disable xmlrpc
*/
if ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) {
include_once(ABSPATH . WPINC . '/class-IXR.php');
class blocking_xmlrpc_server {
function serve_request() {
$response = new IXR_Error( 405, sprintf( __( 'XML-RPC services are disabled on this site.' ) ) );
die( $response->getXml() );
@tott
tott / gist:0cc78e7dcad18024d1c8
Created July 1, 2014 20:35
Create a full list of sites with domain mapping with wp-cli
for i in `wp site list | cut -f 2 | grep -v url`; do wp --url=$i eval 'global $wpdb, $blog_id; $blogname=get_option("blogname"); $blogurl=home_url(); $domains=$wpdb->get_results( "SELECT * FROM {$wpdb->dmtable} WHERE blog_id = $blog_id;" ); foreach( $domains as $data ) { echo $blog_id.",".$blogname.",".$blogurl.",".$data->domain.",".$data->active."\n"; }'; done
@tott
tott / maybe-flush-rewrite-rules.php
Created March 14, 2014 14:26
Flush rewrite rules when it's necessary. This could be put in an init hook or the like and ensures that the rewrite rules option is only rewritten when the generated rules don't match up with the option.
function maybe_flush_rules() {
global $wp_rewrite;
$rewrite_rules = get_option( 'rewrite_rules' );
foreach( $rewrite_rules as $rule => $rewrite ) {
$rewrite_rules_array[$rule]['rewrite'] = $rewrite;
}
$maybe_missing = $wp_rewrite->rewrite_rules();
$missing_rules = false;
$rewrite_rules_array = array_reverse( $rewrite_rules_array, true );
foreach( $maybe_missing as $rule => $rewrite ) {
@tott
tott / harvest-bugger.php
Created February 3, 2014 11:04
For all those people who forget to run their harvest timer. Here's a little script that will bug you when you do. Runs on OSX.
<?php
/**
* Helper script that can be run in cron to bug you when you forgot to run a harvest timer.
* install terminal-notifier via:
* sudo gem install terminal-notifier
* Make sure to adjust your credentials.
* Schedule via crontab -e to run weekdays 9-5
* <star>/10 09-17 * * 1-5 php <path-to-script>
* replace <star> with *
*/
@tott
tott / gist:8639621
Created January 26, 2014 21:17
Speed up wp-admin when there are a lot of terms
add_action( 'admin_init', 'deregister_autosuggest' );
function deregister_autosuggest() {
if ( is_admin() ) {
wp_deregister_script( 'suggest' );
}
}