Skip to content

Instantly share code, notes, and snippets.

@mdawaffe
mdawaffe / i-already-load-jquery-manually.php
Created June 18, 2012 23:50
WordPress (Ill-Advised) Hack: I Already Load jQuery "Manually"
<?php
/*
* Plugin Name: I Already Load jQuery "Manually" Hack
* Plugin URI: https://gist.github.com/2951506
* Description: If you already load jQuery manually (i.e., without using WordPress' script API), this plugin will prevent other plugins that *do* use WordPress' script API from "double" loadin jQuery. There are probably better ways to prevent this unwanted double-loading behavior. If you have to use this plugin, you're probably doing_it_wrong(). Use at your own risk, it probably breaks something.
* Author: mdawaffe
* Version: 0.1
* Author URI: http://blogwaffe.com
* License: GPL2+
@mdawaffe
mdawaffe / option-2-check-the-whole-stack.diff
Created December 13, 2012 03:05
PowerPress Compatibility with Jetpack: Improve the_excerpt/the_content gymnastics
Index: powerpress.php
===================================================================
--- powerpress.php (revision 638166)
+++ powerpress.php (working copy)
@@ -101,8 +101,12 @@
function powerpress_content($content)
{
- global $post, $g_powerpress_excerpt_post_id;
-
@mdawaffe
mdawaffe / option-1-in-the-loop.diff
Created December 13, 2012 03:57
Easy AdSense Lite and Jetpack: Don't show ads (or increment the ezCount) unless we're in the loop.
Index: easy-adsense-lite.php
===================================================================
--- easy-adsense-lite.php (revision 638198)
+++ easy-adsense-lite.php (working copy)
@@ -402,6 +402,7 @@
}
function ezAdSense_content($content) {
+ if (!in_the_loop()) return $content ;
if (!$this->options['allow_feeds'] && is_feed()) return $content ;
@mdawaffe
mdawaffe / option-2-exclude-generated-excerpts.diff
Created December 13, 2012 04:12
Easy AdSense Lite and Jetpack: Don't show ads (or increment the ezCount) when created "generated" excerpts from the post's content.
Index: easy-adsense-lite.php
===================================================================
--- easy-adsense-lite.php (revision 638198)
+++ easy-adsense-lite.php (working copy)
@@ -402,6 +402,8 @@
}
function ezAdSense_content($content) {
+ global $wp_current_filter;
+ if (in_array('get_the_excerpt', (array) $wp_current_filter)) return $content ;
@mdawaffe
mdawaffe / arrow-keys.sh
Created December 2, 2013 02:42
Terminal Arrow Keys Experiment
#!/bin/bash
ENTER=$(printf "%b" "\n")
ESCAPE=$(printf "%b" "\e")
UP_SUFFIX="A"
DOWN_SUFFIX="B"
RIGHT_SUFFIX="C"
LEFT_SUFFIX="D"
while true; do
@mdawaffe
mdawaffe / arrow-keys.sh
Created December 2, 2013 02:42
Terminal Arrow Keys Experiment
#!/bin/bash
uparrow=$'\x1b[A'
downarrow=$'\x1b[B'
leftarrow=$'\x1b[D'
rightarrow=$'\x1b[C'
read -s -n3 -p "Hit an arrow key: " x
case "$x" in
@mdawaffe
mdawaffe / socks4.py
Created December 2, 2013 03:01
SOCKS4 Experiments Failed attempts at restricting a Socks 4/4a/5 proxy to only use Socks 4
#!/usr/bin/env python
import socket
import threading
import select
import SocketServer
class TCPServer( SocketServer.TCPServer ):
allow_reuse_address = True
@mdawaffe
mdawaffe / moon.sh
Created December 5, 2013 02:09
Express the Current Approximate Phase of the Moon as an Emoji Character in UTF-8
#!/bin/bash
# Approximates the phase of the moon using a known new-moon time and a fixed lunar phase of 2551443 seconds.
# Outputs the phase as an emoji in UTF-8
CHARS=(
"\xf0\x9f\x8c\x91" # 0 - NEW
"\xf0\x9f\x8c\x91" # 1 - NEW
"\xf0\x9f\x8c\x92" # 2 - WAXING CRESCENT
@mdawaffe
mdawaffe / Readme.md
Last active September 1, 2023 06:14
Strip HTML markup from a string.

Strip Tags

Strip HTML tags from a string. Does not use (much) regex.

Never loads any resources (<img>, <script>, etc.) referenced in the input.

The treatment of whitespace is probably consistent across browsers but is not guaranteed.

Technique

<?php
if ( $_POST ) {
var_dump( $_POST, $_FILES );
exit;
}
?>
<!DOCTYPE html>
<html>