Instantly share code, notes, and snippets.

View ImageCaptureHelper.java
//MIT License
//Copyright (c) 2015 Karol Wrótniak, Droids On Roids
package pl.droidsonroids.imagehelpers;
import java.io.File;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.ContentResolver;
View remove-post-terms.php
<?php
/**
* Helper function since this function doesn't exist in core
*/
function remove_post_terms( $post_id, $terms_to_remove, $taxonomy ) {
$terms_to_remove = array_map( 'intval', $terms_to_remove );
array_filter( $terms_to_remove, function( $term ) { return ! empty( $term ); } );
// Get the existing terms and only keep the ones we don't want removed
View parent-child-css.php
<?php
add_action( 'wp_enqueue_scripts', function() {
wp_register_style( 'parent-theme', get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-theme', get_stylesheet_uri(), array( 'parent-theme' ) );
} );
View gist:2572405
<?php
add_action( 'generate_rewrite_rules', 'debug_action_generate_rewrite_rules', 1, 1 );
// debug http://core.trac.wordpress.org/browser/trunk/wp-includes/rewrite.php#L1592
// this should only be hit if the rewrite_rules option is empty.
// http://core.trac.wordpress.org/browser/trunk/wp-includes/rewrite.php#L1616
function debug_action_generate_rewrite_rules( $rules ) {
global $debug_action_rules;
error_log( __FUNCTION__ . ' : ' . __LINE__ );
error_log( var_export( $_SERVER, true ) );
error_log( "Rules Option: " . var_export( get_option( 'rewrite_rules' ), true ) );
View query-killer.php
<?php
add_filter( 'posts_where', 'x_kill_search_query', 10, 2 );
function x_kill_search_query( $where, $query ) {
if ( ! is_admin() && $query->is_main_query() ) {
// this is a self-removing callback
remove_filter( current_filter(), __FUNCTION__, 10 );
if ( $query->is_search() ) // only kill the main query
$where = ' AND 1=0 /* Query killed */';
View gist:1297669
<?php
# See bigdawggi's comment below for a good combined example
// Pre-3.3
function cf_google_search_kill_wp_search( $where, $query ) {
global $wp_the_query;
if( ! is_admin() && $query->is_search() && $query === $wp_the_query ) {
$where = ' AND 1=0';
View plugin-deploy.sh
#!/usr/bin/env bash
# args
MSG=${1-'deploy from git'}
BRANCH=${2-'trunk'}
# paths
SRC_DIR=$(git rev-parse --show-toplevel)
DIR_NAME=$(basename $SRC_DIR)
DEST_DIR=~/svn/$DIR_NAME/$BRANCH
View gist:311373
if(!jQuery('<input PLACEHOLDER="1" />')[0].placeholder){ //Uppercase attr for IE
jQuery(':input[placeholder]').each(function(){
var $this = $(this);
if(!$this.val()){
$this.val($this.attr('placeholder'));
$this.addClass('input-placeholder');
}
}).live('focus', function(e){
var $this = $(this);
if($this.hasClass('input-placeholder')){