Skip to content

Instantly share code, notes, and snippets.

@sudar
sudar / apache-error-mailer.py
Last active Mar 8, 2020
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/
View apache-error-mailer.py
#!/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 Sep 8, 2014
Syntastic Syntax Checker for WordPress
View wordpress.vim
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 Aug 31, 2014
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/
View gsheet.py
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())
View svn-to-git.sh
#!/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]`
View sample.log
[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
Code to automatically update version number from readme file in EDD Software licensing addon
View readme.php
<?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 Jun 3, 2020
How To Properly Create Tables In WordPress Multisite Plugins. Explanation at http://sudarmuthu.com/blog/how-to-properly-create-tables-in-wordpress-multisite-plugins/
View 1.php
<?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 Aug 29, 2015
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/
View gist:9749465
<?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 Mar 9, 2014
List of packages that are installed by default in DigitalOcean LAMP image. As of 09-March-2014
View package-list.txt
$ 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
View function.py
def get_length(data):
return len(data)
You can’t perform that action at this time.