Skip to content

Instantly share code, notes, and snippets.

Ashish Kumar ashfame

Block or report user

Report or block ashfame

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@ashfame
ashfame / facebook-like-thumbnail-force-default-image-everywhere.php
Last active Aug 29, 2015
Forcing single thumbnail to be used on Facebook with "Facebook Like Thumbnail" plugin
View facebook-like-thumbnail-force-default-image-everywhere.php
<?php
/**
* Plugin Name: Facebook Like Thumbnail - Force Default Image everywhere
* Plugin URI: https://gist.github.com/ashfame/62f59587aaa5c8ecb1ce
* Description: Forces the default image to be used as FB Thumbnail for every page
* Author: Ashfame
* Author URI: http://ashfame.com/
*/
@ashfame
ashfame / synthesis.php
Created Sep 3, 2014
WP CLI commands available on web-synthesis servers
View synthesis.php
<?php
function synth_clear_mem_check () {
delete_transient( 'synthesis_memory_check' );
}
add_action('update_option_active_plugins', 'synth_clear_mem_check');
// If we're running from WP CLI, add our CLI commands.
if ( defined( 'WP_CLI' ) && WP_CLI ) {
class Synthesis_Ops_Commands extends WP_CLI_Command {
/**
View filtering-expiration-transient-wordpress.php
<?php
add_action( 'set_transient_my_transient', function( $value, $expiration ) {
$desired_expiration = 600;
if ( $expiration != $desired_expiration ) {
set_transient( 'my_transient', $value, $desired_expiration );
}
});
@ashfame
ashfame / plugin.php
Created Jan 20, 2015
Initial pass at a plugin which reduces the extra number of queries triggered by plugins to look for non-existent options in options table. Use this as a starting point for what you are trying to do.
View plugin.php
<?php
/**
* Plugin Name: AnattaDesign Site Optimizer
* Plugin URI: http://anattadesign.com/
* Description: This plugin optimizes the site by reducing the extra number of queries triggered by plugins to look for non-existent options in options table
* Version: 0.1
* Author: Anatta Design
* Author URI: http://anattadesign.com/
*/
@ashfame
ashfame / override-wp-cli-command.php
Last active Aug 29, 2015
Example of how to override a WP-CLI command
View override-wp-cli-command.php
<?php
if ( defined('WP_CLI') && WP_CLI ) {
class Transient_Mod_Command extends Transient_Command {
public function delete_all() {
// new definition of delete-all subcommand
}
}
@ashfame
ashfame / randomize_preferred_nodes_each_node.php
Created May 3, 2015
Simple algorithm for picking up 3-7 preferred nodes for each node among a pool of nodes, so that its a little uneven (every node has different number of preferred nodes) but overall there is a balance in distribution.
View randomize_preferred_nodes_each_node.php
$nodes = array();
for ( $i = 1; $i <= 100; $i++ ) {
$nodes[ $i ] = '';
}
print_r( $nodes );
foreach ( $nodes as $key => &$node ) {
$random_keys_selection = array_rand( $nodes, mt_rand( 3, 7 ) );
var_dump( $random_keys_selection );
@ashfame
ashfame / gist:1370753
Created Nov 16, 2011
Bash script to generate a html file describing all tables in a database
View gist:1370753
#!/bin/bash
#Change your db username, password & database name
if [ -f ~/Desktop/db_schema.html ]; then
rm ~/Desktop/db_schema.html
fi
for i in `mysql -B -N -uroot -proot dbname -e 'show tables;'`; do
echo "<a href='#$i'>$i</a><br />" >> /tmp/$$.nav.html
@ashfame
ashfame / wpautop-control.php
Created Dec 31, 2011
Function to remove wpautop filter for specific post IDs
View wpautop-control.php
/**
* Function to remove wpautop filter for specific post IDs
*/
add_action( 'init', 'do_ma_thang' );
function do_ma_thang() {
global $wp_query;
$exclusion = array( 1, 5, 7 ); // add post IDs here
@ashfame
ashfame / example.php
Created Jan 24, 2012
Changing postmeta fields programmatically
View example.php
<pre><?php
require 'wp-load.php';
$postmeta_field_name = 'video_url'; // fill it
echo $query = "SELECT * FROM {$wpdb->postmeta} WHERE meta_key = '$postmeta_field_name';";
$data = $wpdb->get_results( $query );
View svn-commands.sh
# Count no of files in repo
svn info -R --xml file:///path/to/rep | grep kind=\"file\"|wc -l
# SVN command to give commit authors list and save it in author-transform.txt
svn log -q | awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2" = "$2" <"$2">"}' | sort -u > authors-transform.txt
You can’t perform that action at this time.