Skip to content

Instantly share code, notes, and snippets.

View rmpel's full-sized avatar

Remon Pel rmpel

View GitHub Profile
@rmpel
rmpel / mu-plugin-clarify-redirect.php
Last active December 9, 2015 13:12
See what function is causing a redirect in WordPress
<?php
add_filter('wp_redirect', 'clarify_redirect');
function clarify_redirect( $url ) {
$callers = debug_backtrace();
foreach ($callers as $i => $caller) {
header("X-Caller-{$i}: ". $caller['function']);
}
return $url;
}
@rmpel
rmpel / svntag.sh
Created December 10, 2015 13:47
script to easily tag a Subversion project
#!/bin/bash
SVN=/usr/local/bin/svn
[ ! -f "$SVN" ] && SVN=/usr/bin/svn
trunk_or_branch_status () {
echo "Status on SVN ($1)"
TRUNKREV=` svn info "$1" | grep "Last Changed Rev" | egrep -o [0-9]+ `
TAGSREV=` svn info "$2"/tags | grep "Last Changed Rev" | egrep -o [0-9]+ `
[ $TRUNKREV -gt $TAGSREV ] && echo There are changes not yet tagged \! \( HEAD: $TRUNKREV, Tags: $TAGSREV \) && svn log -r $TAGSREV:$TRUNKREV
[ $TRUNKREV -le $TAGSREV ] && echo No action needed\!
@rmpel
rmpel / anonymizeIp-google-analytics-unless-consent.js
Last active December 17, 2015 14:52
This snippet will anonymize IP addresses for Google Analytics (Universal, analytics.js) unless a cookie eucookieconsent is set with value 1.You wil need to put this in the top of the head of your website, or at leaset BEFORE analytics is loaded.
@rmpel
rmpel / diacritics.js
Created January 18, 2016 14:36
JavaScript to replace Diacritics (international characters, accented characters) with their ASCII counterpart
;
(function (s) {
s.toAscii = function () {
var diacritics = [
{'base':'A', 'letters':/[\u0041\u24B6\uFF21\u00C0\u00C1\u00C2\u1EA6\u1EA4\u1EAA\u1EA8\u00C3\u0100\u0102\u1EB0\u1EAE\u1EB4\u1EB2\u0226\u01E0\u00C4\u01DE\u1EA2\u00C5\u01FA\u01CD\u0200\u0202\u1EA0\u1EAC\u1EB6\u1E00\u0104\u023A\u2C6F]/g},
{'base':'AA','letters':/[\uA732]/g},
{'base':'AE','letters':/[\u00C6\u01FC\u01E2]/g},
{'base':'AO','letters':/[\uA734]/g},
{'base':'AU','letters':/[\uA736]/g},
{'base':'AV','letters':/[\uA738\uA73A]/g},
@rmpel
rmpel / numberformat.js
Created May 4, 2016 06:42
Format numbers to human-readable format and money format (Euro, but easily adaptable)
if (!Number.prototype.format) {
Number.prototype.format = function(decimals, decimal_separator, thousands_separator, prefix, suffix) {
decimals = decimals || 0;
decimal_separator = decimal_separator || ',';
thousands_separator = thousands_separator || '.';
prefix = prefix || "";
suffix = suffix || "";
var str = this.toFixed(decimals).toString().split('.');
var parts = [];
@rmpel
rmpel / wp-schedule-timer.php
Last active May 4, 2016 15:27
WordPress Custom schedule timer
<?php
add_filter('cron_schedules', function( $schedules ) {
$schedules['quarterly'] = array(
"interval" => HOUR_IN_SECONDS/4,
"display" => "Every 15 minutes"
);
return $schedules;
});
@rmpel
rmpel / git-svn-user-map.sh
Created May 15, 2016 07:37
Create user-map for conversion from SVN to GIT
#!/bin/bash
svn log -q | awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2" = "$2" <"$2"@example.com>"}' | sort -u > users.txt
@rmpel
rmpel / dutch-holidays.php
Last active June 1, 2016 10:20
Dutch off-of-work-holiday-days
<?php
/**
* @class Returns a list of DUTCH holidays on which we brave people stop and do nothing for a day... just 'cause :)
*/
class Holidays {
/**
* Returns all dates on which we Dutch people get a day off of work.
* @param int $year The year for which to get the list of holidays
* @return Array The list of holidays, associative array [holiday name] => [date in d-m-Y format]
*/
@rmpel
rmpel / block-tel-in-incapable-browser.js
Last active June 14, 2016 07:59
block InternetExplorer <= 11 w/o Skype tel: links
(function(w) {
w.cantel = true; // set true for all browsers
if ("ActiveXObject" in w) { // if IE <= 11
w.cantel = false;
var activex;
try { activex = !!new ActiveXObject("Skype.Detection"); } catch (e) { activex = false; }; // test for skype
if (activex) {
w.cantel = true;
}
}
@rmpel
rmpel / jQuery.append-to-attribute.js
Created September 5, 2016 09:26
Append to attribute (jQuery)
(function($){
$.fn.appendAttr = function(attr, value, cat) {
var cat = cat || ",";
return $(this).each(function(){
var a = $(this).attr(attr) || "";
if (a) a = a + cat;
a = a + value;
$(this).attr(attr, a);
});
}