Skip to content

Instantly share code, notes, and snippets.

@sudar
sudar / apache-error-mailer.py
Last active March 8, 2020 17:57
Automatically send unique errors (with count) from Apache error log as email. Details at http://sudarmuthu.com/blog/automatically-send-unique-errors-with-count-from-apache-error-log-as-email/
#!/usr/bin/env python
import sys
import mandrill
MANDRILL_API_KEY = "api-key"
EMAIL_FROM = "your@email.com"
EMAIL_TO = "your@email.com"
EMAIL_SUBJECT = "Error Log"
@sudar
sudar / wordpress.vim
Created September 8, 2014 16:44
Syntastic Syntax Checker for WordPress
if exists("g:loaded_syntastic_wordpress_phpcs_checker")
finish
endif
let g:loaded_syntastic_wordpress_phpcs_checker = 1
" Use PHP's phpcs checker
runtime! syntax_checkers/php/phpcs.vim
call g:SyntasticRegistry.CreateAndRegisterChecker({
\ 'filetype': 'wordpress',
@sudar
sudar / gsheet.py
Created August 31, 2014 07:18
Read data from Google Sheet into a Python Pandas DataFrame. Details at http://sudarmuthu.com/blog/read-data-from-google-sheet-into-a-python-pandas-dataframe/
import gspread
import pandas
gc = gspread.login('my@email.com', 'supersecretepassword')
book = gc.open('Spreadsheet name')
sheet = book.sheet1 #choose the first sheet
dataframe = pandas.DataFrame(sheet.get_all_records())
@sudar
sudar / svn-to-git.sh
Created August 27, 2014 06:32
SVN to git
#!/bin/bash
################################################################################
# Clone the svn Plugin repo into github
# Author: Sudar <http://sudarmuthu.com>
#
# License: Beerware ;)
#
# Usage:
# ./path/to/clone-from-svn-to-git.sh [-p plugin-name] [-a authors-file] [-u svn-username] [-g github-repo-url]`
[Sat May 31 10:24:44 2014] [error] [client 127.0.0.1] Request header read timeout
@sudar
sudar / readme.php
Created May 8, 2014 05:59
Code to automatically update version number from readme file in EDD Software licensing addon
<?php
add_filter( 'edd_sl_license_readme_response', function( $response, $download, $readme ) {
$meta_version = get_post_meta( $download->ID, '_edd_sl_version', true );
if ( '' != $readme['stable_tag'] && $meta_version != $readme['stable_tag'] ) {
update_post_meta( $download->ID, '_edd_sl_version', $readme['stable_tag']);
}
return $response;
}, 10, 3 );
?>
@sudar
sudar / 1.php
Last active September 10, 2022 17:59
How To Properly Create Tables In WordPress Multisite Plugins. Explanation at http://sudarmuthu.com/blog/how-to-properly-create-tables-in-wordpress-multisite-plugins/
<?php
// Creating tables in Single site installations
function on_activate() {
create_table();
}
function create_table() {
global $wpdb;
$table_name = $wpdb->prefix . 'table_name';
@sudar
sudar / gist:9749465
Last active August 29, 2015 13:57
Code to prevent users from adding new terms to custom taxonomy in WordPress. More details at http://sudarmuthu.com/blog/prevent-users-from-adding-new-terms-to-custom-taxonomy-in-wordpress/
<?php
add_action( 'pre_insert_term', 'prevent_terms', 1, 2 );
function prevent_terms ( $term, $taxonomy ) {
if ( 'areas' === $taxonomy && !current_user_can( 'activate_plugins' ) ) {
return new WP_Error( 'term_addition_blocked', __( 'You cannot add terms to this taxonomy' ) );
}
return $term;
}
@sudar
sudar / package-list.txt
Created March 9, 2014 03:13
List of packages that are installed by default in DigitalOcean LAMP image. As of 09-March-2014
$ dpkg --get-selections | grep -v deinstall
acpid install
adduser install
anacron install
apache2-mpm-prefork install
apache2-utils install
apache2.2-bin install
apache2.2-common install
apt install
@sudar
sudar / function.py
Last active December 22, 2015 21:39
Writing Pig UDF function using Python. Details at http://sudarmuthu.com/blog/writing-pig-udf-functions-using-python
def get_length(data):
return len(data)