Skip to content

Instantly share code, notes, and snippets.

View martijngastkemper's full-sized avatar

Martijn Gastkemper martijngastkemper

View GitHub Profile
@martijngastkemper
martijngastkemper / block-user-agent.apacheconf
Last active December 25, 2015 18:29
Solution to block an user-agent with htaccess. In this example 80legs crawler is blocked.
BrowserMatchNoCase 80legs bad_bot
Order Deny,Allow
Deny from env=bad_bot
@martijngastkemper
martijngastkemper / .htaccess
Last active October 3, 2016 09:29
Htaccess lines to permanently redirect secondary domains to a primary domain. For example: www.example.com/foo will redirect to example.nl/foo. And a lot of other examples.
# Only necessary for website not implemented with FifthGear
RewriteEngine On
# Rewrite www.example.nl and example.com to example.nl
RewriteCond %{HTTP_HOST} www.example.nl [NC,OR]
RewriteCond %{HTTP_HOST} example.com [NC]
RewriteRule ^(.*)$ http://example.nl/$1 [R=301,L]
# Rewrite example.nl to www.example.nl
RewriteCond %{HTTP_HOST} ^example.nl [NC]
@martijngastkemper
martijngastkemper / .gitignore
Last active December 31, 2015 12:39
Backup and restore cPanel e-mail accounts by domain. You can use this script to move e-mailboxes between cPanel accounts.
cpanel-mailbox-files
@martijngastkemper
martijngastkemper / update-wordpress.sh
Last active August 29, 2015 13:56
Update WordPress submodule to new version (tag).
cd folder-containing-wordpress
git fetch --tags
git checkout x.y.x
cd ../
git add folder-containing-wordpress
git commit -m "Upgrade WordPress to x.y.z"
git push
# To fetch a submodule when you changed the version locally, git pull isn't enough
cd folder-containing-wordpress
@martijngastkemper
martijngastkemper / postMash.js
Last active August 29, 2015 13:56
Fixes WordPress plugin "PostMash Custom" when WordPress is installed in "different-dir"
new Ajax('../wp-content/plugins/postmash-custom/saveList.php', {
new Ajax('/wp-content/plugins/postmash-custom/saveList.php', {
@martijngastkemper
martijngastkemper / dumpdatabase.bash
Last active August 29, 2015 13:57
Dump MySQL database and remove definer. Definer must be an existing user. So when moving a database to another server the trigger can fail when the definer doesn't exists.
mysqldump database-name | sed -e 's/DEFINER[ ]*=[ ]*[^*]*\*/\*/' > output.sql
@martijngastkemper
martijngastkemper / wp-tell-a-friend-popup-form.php
Last active August 29, 2015 13:58
Make the [Tell a friend] (http://www.gopiplus.com/work/2012/05/21/wordpress-plugin-wp-tell-a-friend-popup-form) plugin for WordPress work with an changed WordPress source directory. Useful for WordPress in Git repositories
# Not working
wp_enqueue_style( 'tell-a-friend', get_option('siteurl').'/wp-content/plugins/wp-tell-a-friend-popup-form/tell-a-friend.css');
wp_enqueue_script( 'tell-a-friend-form', get_option('siteurl').'/wp-content/plugins/wp-tell-a-friend-popup-form/tell-a-friend-form.js');
wp_enqueue_script( 'tell-a-friend-popup', get_option('siteurl').'/wp-content/plugins/wp-tell-a-friend-popup-form/tell-a-friend-popup.js');
# Working
wp_enqueue_style( 'tell-a-friend', plugins_url( 'tell-a-friend.css', __FILE__ ) );
wp_enqueue_script( 'tell-a-friend-form', plugins_url( 'tell-a-friend-form.js', __FILE__ ) );
wp_enqueue_script( 'tell-a-friend-popup', plugins_url( 'tell-a-friend-popup.js', __FILE__ ) );
@martijngastkemper
martijngastkemper / ajax.php
Last active August 29, 2015 13:58
Fixes WordPress plugin "File Un-Attach" when WordPress is installed in "different-dir"
# Change
require_once '../../../wp-load.php';
# into
require_once '../../../different-dir/wp-load.php';
@martijngastkemper
martijngastkemper / dump-triggers
Created April 22, 2014 08:51
Dump MySQL triggers
mysqldump --routines --no-create-info --no-data --no-create-db --skip-opt <database> > outputfile.sql
@martijngastkemper
martijngastkemper / zabbix.php
Last active August 29, 2015 14:01
Zabbix API uitproberen
<?php
// load ZabbixApi (http://zabbixapi.confirm.ch/)
require 'ZabbixApiAbstract.class.php';
require 'ZabbixApi.class.php';
try {
// connect to Zabbix API
$api = new ZabbixApi("...");