Skip to content

Instantly share code, notes, and snippets.

View ashfame's full-sized avatar
💭
What parts of our society are best governed by code?

Ashish Kumar ashfame

💭
What parts of our society are best governed by code?
View GitHub Profile
@ashfame
ashfame / facebook-like-thumbnail-force-default-image-everywhere.php
Last active August 29, 2015 14:01
Forcing single thumbnail to be used on Facebook with "Facebook Like Thumbnail" plugin
<?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 September 3, 2014 16:49
WP CLI commands available on web-synthesis servers
<?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 {
/**
<?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 January 20, 2015 23:30
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.
<?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 August 29, 2015 14:19
Example of how to override a WP-CLI command
<?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 15:19
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.
$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 November 16, 2011 17:32
Bash script to generate a html file describing all tables in a database
#!/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 December 31, 2011 09:56
Function to remove wpautop filter for specific post IDs
/**
* 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 January 24, 2012 08:00
Changing postmeta fields programmatically
<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 );
@ashfame
ashfame / svn-commands.sh
Created February 24, 2012 16:58
SVN commands
# 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