Skip to content

Instantly share code, notes, and snippets.

@coolamit
coolamit / class-faker.php
Created May 19, 2020 16:29
Dummy post generation in WordPress for testing features.
<?php
/**
* Faker class to generate dummy posts in WordPress
*
* @author Amit Gupta <http://amitgupta.in/>
*
* @since 2019-11-28
*/
namespace iG\Inc\Utilities;
@coolamit
coolamit / db-unicode-conversion.php
Last active January 4, 2019 00:29
PHP script to convert data from latin1 to utf8. The script expects table columns to already be on utf8 charset and 'utf8_unicode_ci' collation. It just re-encodes data from latin1 to utf8 so that the data is legible instead of appearing as gibberish.
<?php
/**
* PHP cli script to re-encode data in a MySQL database from latin1 to utf8.
* The script expects table columns to already be on utf8 charset and 'utf8_unicode_ci' collation.
* It just re-encodes data from latin1 to utf8 so that the data is legible instead of appearing as gibberish.
*
* @author Amit Gupta <http://amitgupta.in/>
* @copyright 2019 Amit Gupta <http://amitgupta.in/>
* @licence GPL v3
*/
@coolamit
coolamit / ig-sample-plugin.php
Created January 23, 2014 10:21
A sample WordPress plugin - for evaluation of code refactoring
<?php
/*
Plugin Name: iG: Sample Plugin
Plugin URI: http://igeek.info/
Description: This is a sample plugin for code evaluation only
Version: 1.0
Author: Amit Gupta
License: GPL v2
*/
@coolamit
coolamit / wp-config.php
Created August 27, 2013 15:40
Code to plug in wp-config.php before any constants are defined, so that wp-cli doesnt throw any errors as $_SERVER wouldn't be available when running a wp-cli script
<?php
//initial code to set error reporting, xdebug customization etc.
if ( defined('WP_CLI') && WP_CLI ) {
if( empty( WP_CLI::get_runner()->config['url'] ) ) {
error_log( "You need to set url." );
exit;
}
<?php
/**
* This function accepts an array and joins all values in a string separated by
* a comma except the last value which is preceeded by 'and' instead of a comma
*/
function to_sentence( $array = array() ) {
if( empty( $array ) || ! is_array( $array ) ) {
return $array;
}
@coolamit
coolamit / gmail-svn-diff-colorize.js
Created October 19, 2012 19:35
SVN diff colorizer for Gmail
// ==UserScript==
// @name SVN Diff Colorizer for GMail (based almost wholly on Beanstalk Diff Colorizer for Gmail - http://userstyles.org/styles/14853)
// @namespace http://userstyles.org
// @description Adds colorization to SVN diffs received via Could be made to work with your webmail of choice, and probably some other SVN hosts, with minimal fuss.
// @author Matt Gillooly
// @modifiedBy 2012-10-21 Amit Gupta
// @include http://mail.google.com/*
// @include https://mail.google.com/*
// @include http://*.mail.google.com/*
// @include https://*.mail.google.com/*