Skip to content

Instantly share code, notes, and snippets.

View devfreddy's full-sized avatar

Michael Frederick devfreddy

View GitHub Profile
@devfreddy
devfreddy / WP_MaterializedViews.php
Created June 28, 2013 20:35
Crude php script to create "materialized views" of Wordpress Custom Post Types with their Post Meta data.
<?php
require '../../../../wp-load.php';
function post_type_mv( $post_type , $keys = array('post_id')){
global $wpdb;
$post_meta_sql = "SELECT DISTINCT pm.meta_key
FROM wp_posts p
LEFT OUTER JOIN wp_postmeta pm ON pm.post_id = p.ID
WHERE p.post_type = '$post_type'";
$post_meta = array_flip($wpdb->get_col($post_meta_sql));
//error_log(print_r($post_meta, TRUE));
@devfreddy
devfreddy / fix_guest_additions.sh
Created July 17, 2013 04:04
If your mouse doesn't work on a Ubuntu Guest with Virtualbox, here's what seems to be the only way to get things working again.
#Virtualbox, Ubuntu and Guest Additions often get cranky, here's how to fix them so you're bloody mouse works again.
sudo apt-get install -f
sudo apt-get clean
sudo apt-get update
sudo apt-get install linux-headers-$(uname -r)
#OR
sudo apt-get install --reinstall linux-headers-$(uname -r)
sudo /etc/init.d/vboxadd setup
@devfreddy
devfreddy / wp_users_utils.sql
Last active December 31, 2015 13:19
Wordpress Users and UserMeta SQL.
--- Date last logged in ---
SELECT u.ID, u.user_email
, MAX(CASE WHEN um.meta_key = 'first_name' then um.meta_value ELSE NULL END) as first_name
, MAX(CASE WHEN um.meta_key = 'last_name' then um.meta_value ELSE NULL END) as last_name
, MAX(CASE WHEN um.meta_key = '_last_login' then um.meta_value ELSE NULL END) as last_login
FROM wp_users u LEFT JOIN wp_usermeta um ON ( um.user_id = u.ID)
WHERE um.meta_key in ('first_name', 'last_name','_last_login')
GROUP BY u.ID
ORDER BY last_login DESC
LIMIT 1000
@devfreddy
devfreddy / gist:9782562
Last active August 29, 2015 13:57
Wordpress Term/Tax Group by Locations
SELECT parent.name, t.name, COUNT( * )
FROM wp_posts AS p
INNER JOIN wp_term_relationships AS tr ON p.ID = tr.object_id
INNER JOIN wp_term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id
INNER JOIN wp_terms AS t ON tt.term_id = t.term_id
LEFT OUTER JOIN wp_terms AS parent ON tt.parent = parent.term_id
WHERE p.post_type = 'clubfoot_patient'
AND tt.taxonomy = 'medrec_locations'
AND ( parent.name IN ( 'Rwanda', 'Ethiopia', 'India' ) OR t.name IN ( 'Rwanda', 'Ethiopia', 'India' ) )
GROUP BY parent.name, t.name
@devfreddy
devfreddy / marionette_app_template.js
Created September 12, 2014 17:47
Marionette App Template
$(window).load(function () {
if (!this.cure || typeof this.cure !== 'object'){
this.cure = {};
}
this.cure.donate = (function () {
'use strict';
var MyApp = new Backbone.Marionette.Application();
MyApp.onStart = function () {
};
@devfreddy
devfreddy / wp-config.php.local
Last active February 10, 2016 16:19
Wordpress dynamically set site url for local development
<?php
/*
* Still requires the nginx server_name to be set to one of these
* For names, still requires hosts file to be set
* Just updates one thing for you automatically so if your local ip changes you don't have to change so many things
*
*/
$ip = $_SERVER['SERVER_ADDR'];
$identifiers = array( $_SERVER['HTTP_HOST'], $_SERVER['REMOTE_ADDR'], $_SERVER['SERVER_NAME'] );
$aliases = array('local.site.org', $ip . '.xip.io', $ip, '127.0.0.1', '127.0.0.1.xip.io');
@devfreddy
devfreddy / 0_reuse_code.js
Last active August 29, 2015 14:20
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@devfreddy
devfreddy / gist:a71ea992241f2fdb6afb
Created June 16, 2015 19:22
Stripe Event listing
customer.created
customer.deleted
customer.updated
customer.source.created
customer.source.deleted
customer.source.updated
customer.subscription.deleted
customer.subscription.created
customer.subscription.updated
charge.captured
@devfreddy
devfreddy / cloneAndFork.sh
Created February 20, 2020 17:21
Clone and Fork New Relic One open source apps
#!/usr/bin/env bash
BASE="git@github.com:newrelic"
declare -a arr=(
"nr1-bigeventui"
"nr1-bootstrap-theme"
"nr1-browser-analyzer"
"nr1-cloud-optimize"
"nr1-community"
@devfreddy
devfreddy / instructions.md
Created August 20, 2020 13:32
Monocle + Dejavu

Combining Monocle with Dejavu

docker-compose.yml

To the elastic config:

Remove:

expose: