Skip to content

Instantly share code, notes, and snippets.

@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 / exclude-attachments.php
Created November 17, 2018 05:37
Exclude attachments from getting deleted using the Bulk Delete Attachments add-on for Bulk Delete plugin
<?php
add_filter( 'bd_delete_attachment_excluded_attachment_ids', 'prefix_exclude_attachment_ids_from_deletion' );
function prefix_exclude_attachment_ids_from_deletion( $attachment_ids ) {
return array(
100,
111,
112,
);
}
@sudar
sudar / Customfile-memory.rb
Last active November 1, 2018 11:01
Mapping plugin folder in VVV using shared folders. Details at http://sudarmuthu.com/blog/mapping-plugin-folder-in-vvv-using-shared-folders/
config.vm.provider "virtualbox" do |v|
v.memory = 2048
end
@sudar
sudar / capability.php
Last active August 7, 2017 12:39
Change the capability that is required for viewing email logs
<?php
function wpel_change_email_log_user_role( $capability ) {
return 'manage_options' // change this to the capability that you want.
}
add_filter( 'el_view_email_log_capability', 'wpel_change_email_log_user_role' );
<?php
/**
* Expand short urls
*
* @param <string> $url - Short url
* @return <string> - Longer version of the short url
*/
function expand_url($url){
//Get response headers
$response = get_headers($url, 1);
@sudar
sudar / dump-taxonomies.php
Last active January 30, 2017 11:15
Dump All Taxonomies for debugging
<?php
/**
* Plugin Name: Dump Taxonomy
* Plugin URI: http://bulkwp.com
* Description: Dump all Taxonomy for debugging
* Version: 0.1
* License: GPL
* Author: Sudar
* Author URI: http://sudarmuthu.com/
*/
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
Uri screenshotUri = Uri.parse(path);
sharingIntent.setType("image/png");
sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
startActivity(Intent.createChooser(sharingIntent, "Share image using"));
@sudar
sudar / last-page.php
Last active June 18, 2016 06:11
How to find if you are on the last page of a multi-page post in WordPress. Explanation at http://sudarmuthu.com/blog/how-to-find-if-you-are-on-the-last-page-of-a-multi-page-post-in-wordpress/
<?php
/**
* Is the current page the last page of the multi-page post.
*
* @return bool True if last page, False otherwise.
*/
function is_last_page() {
global $page, $numpages, $multipage;
if ( $multipage ) {
@sudar
sudar / arrays.txt
Last active January 30, 2016 11:59
Awk command to remove duplicate lines, based on a field. Explanation at http://sudarmuthu.com/blog/remove-duplicate-lines-based-on-a-field
# Before starting
x = {}
# After line 1
x = {
CTO => 1
}
# After line 2
x = {
@sudar
sudar / array.js
Created July 5, 2012 16:35
Improve JavaScript performance in V8
a = new Array();
for (var b = 0; b < 10; b++) {
a[0] |= b;
}
a = new Array();
a[0] = 0; // just this change alone make code 2x faster
for (var b = 0; b < 10; b++) {
a[0] |= b;