Skip to content

Instantly share code, notes, and snippets.

View mjangda's full-sized avatar

Mohammad Jangda mjangda

View GitHub Profile
@koral--
koral-- / ImageCaptureHelper.java
Last active January 16, 2019 10:57
Helper for sending ACTION_IMAGE_CAPTURE intent and retrieve its results. Handles all low level operations
//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;
@mjangda
mjangda / remove-post-terms.php
Created July 2, 2012 09:12
Remove multiple terms from a post
<?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
@mjangda
mjangda / parent-child-css.php
Last active October 6, 2015 10:17
Properly queueing parent and child style.css, props Viper007Bond
<?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' ) );
} );
@tott
tott / gist:2572405
Created May 1, 2012 23:39
debugging WordPress rewrite rules
<?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 ) );
@mjangda
mjangda / query-killer.php
Created February 10, 2012 19:54
Kills WordPress search query
<?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 */';
@Viper007Bond
Viper007Bond / gist:1297669
Created October 19, 2011 07:27
Determining if modifying the main query or not in WordPress
<?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';
@scribu
scribu / plugin-deploy.sh
Created August 4, 2011 12:18
Plugin deploy
#!/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
@westonruter
westonruter / gist:311373
Created February 22, 2010 19:21
jQuery fallback implementation of HTML5 placeholder attribute
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')){