Skip to content

Instantly share code, notes, and snippets.

Thorsten Ott tott

Block or report user

Report or block tott

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@tott
tott / ip_in_range.php
Created Nov 27, 2013
php check if IP is in given network range
View ip_in_range.php
/**
* Check if a given ip is in a network
* @param string $ip IP to check in IPV4 format eg. 127.0.0.1
* @param string $range IP/CIDR netmask eg. 127.0.0.0/24, also 127.0.0.1 is accepted and /32 assumed
* @return boolean true if the ip is in this range / false if not.
*/
function ip_in_range( $ip, $range ) {
if ( strpos( $range, '/' ) == false ) {
$range .= '/32';
}
@tott
tott / gist:3895832
Created Oct 15, 2012
create cpu load in python
View gist:3895832
#!/usr/bin/env python
"""
Produces load on all available CPU cores
"""
from multiprocessing import Pool
from multiprocessing import cpu_count
def f(x):
while True:
View gist:7125b5cfa1bd48d8da0e9ad89256c802
polybar config
[module/date]
type = custom/script
exec = ~/scripts/popup-calendar.sh
interval = 5
click-left = ~/scripts/popup-calendar.sh --popup
format-background = ${colors.alt-background}
format-foreground = ${colors.alt-foreground}
label = %output:25%
@tott
tott / debug_http_requests.php
Created May 22, 2019
debug_http_requests.php Debug WordPress http api requests
View debug_http_requests.php
<?php
add_action( 'http_api_debug', 'my_http_api_debug', 10, 5 );
function my_http_api_debug( $response, $type, $class, $args, $url ) {
error_log( 'requested url: ' . var_export( $url, true ) );
error_log( 'arguments: ' . var_export( $args, true ) );
error_log( 'http response : ' . var_export( $response, true ) );
}
@tott
tott / minions-post-pusher.php
Last active Apr 24, 2019
WP-Minions ( https://github.com/tott/WP-Minions/tree/alter-job-data ) for multisite syndication to one site.
View minions-post-pusher.php
<?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
*/
@tott
tott / read-backlight.py
Created Nov 22, 2018
Read backlight for x230 / x330 taobao FHD mod
View read-backlight.py
#!/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:7767218
Created Dec 3, 2013
.htaccess rule to force www and preserving the protocol http/https
View gist:7767218
# Force www
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
@tott
tott / gist:a10bebe067d517455e423eb32f7d1d3d
Created Oct 16, 2018
Sending multipart mail with wp_mail (untested)
View gist:a10bebe067d517455e423eb32f7d1d3d
<?php
$to = "receipt@domain.com";
$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 Jul 10, 2018
WordPress options table size Nagios monitor
View options-monitor.sh
#!/bin/bash
OPTIND=1
verbose=0
dbuser=""
dbpasswd=""
while getopts "vh?U:P:H:" opt; do
case "$opt" in
@tott
tott / secure-auth-cookies.php
Last active Feb 17, 2017
Encrypt WordPress auth cookies
View secure-auth-cookies.php
<?php
function sav_encrypt_cookie( $decrypted ) {
$encrypted = mcrypt_encrypt( MCRYPT_RIJNDAEL_256, substr( AUTH_SALT, 0, 32 ), $decrypted, MCRYPT_MODE_ECB, mcrypt_create_iv( mcrypt_get_iv_size( MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB ), MCRYPT_RAND ) );
return trim( base64_encode( $encrypted ) );
}
function sav_decrypt_cookie( $encrypted ) {
$decrypted = mcrypt_decrypt( MCRYPT_RIJNDAEL_256, substr( AUTH_SALT, 0, 32 ), base64_decode( $encrypted ), MCRYPT_MODE_ECB, mcrypt_create_iv( mcrypt_get_iv_size( MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB ), MCRYPT_RAND ) );
return trim( $decrypted );
You can’t perform that action at this time.