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 / harvest-bugger.php
Created Feb 3, 2014
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.
View harvest-bugger.php
<?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 Jan 26, 2014
Speed up wp-admin when there are a lot of terms
View gist:8639621
add_action( 'admin_init', 'deregister_autosuggest' );
function deregister_autosuggest() {
if ( is_admin() ) {
wp_deregister_script( 'suggest' );
}
}
@tott
tott / gist:8517558
Created Jan 20, 2014
indexOf was added to the ECMA-262 standard in the 5th edition; as such it may not be present in all browsers. You can work around this by utilizing the following code at the beginning of your scripts. This will allow you to use indexOf when there is still no native support. This algorithm matches the one specified in ECMA-262, 5th edition, assum…
View gist:8517558
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function (searchElement, fromIndex) {
if ( this === undefined || this === null ) {
throw new TypeError( '"this" is null or not defined' );
}
var length = this.length >>> 0; // Hack to convert object.length to a UInt32
fromIndex = +fromIndex || 0;
@tott
tott / gist:7908001
Created Dec 11, 2013
Get a space separated list of all hosts in an apache config so you can add them to your hosts file
View gist:7908001
#!/bin/bash
grep -E "Server(Name|Alias)" httpd.conf | sort | uniq | cut -d " " -f 6 | tr "\n" " "
@tott
tott / compare-urls.sh
Created Dec 10, 2013
Compare html served by different servers. This script will first get the page from the source ip and extract a list of links on this output. then it will compare the output of each link for both servers.
View compare-urls.sh
#!/bin/bash
ip1='FILL-SOURCE-IP'; ip2='FILL-DEST-IP'; host='FILL-HOSTNAME'; curl http://$host | grep -o '<a.*href=.*>' | grep "http://$host" | sed -e 's/<a .*href=['"'"'"]//' -e 's/["'"'"'].*$//' -e '/^$/ d' > links.txt; for link in `cat links.txt`; do path=`echo -n $link | cut -d "/" -f 4-`; curl --header "Host: $host" "http://$ip1/$path" > ip1.html; curl --header "Host: $host" "http://$ip2/$path" > ip2.html; echo; echo "Diff http://$ip1/$path"; echo; diff ip1.html ip2.html; done
@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 / 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 / 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 );
@tott
tott / functions.php
Created Nov 15, 2013
validate if a path is a subfolder of WP_CONTENT_DIR
View functions.php
/**
* Validate that a given path is a child of the WP_CONTENT_DIR
* @param string $path path to check
* @return boolean true/false
*/
function sav_path_is_valid( $path ) {
if ( !defined( WP_CONTENT_DIR ) )
return false;
$start = 0;
View alter-robots-txt.php
add_filter( 'robots_txt', 'sav_add_sitemap_to_robots' );
function sav_add_sitemap_to_robots( $robots ) {
$robots .= 'Sitemap: ' . site_url( 'sitemap_index.xml' );
return $robots;
}
You can’t perform that action at this time.