Skip to content

Instantly share code, notes, and snippets.

View Kevinlearynet's full-sized avatar

Kevinleary.net Kevinlearynet

View GitHub Profile
@Kevinlearynet
Kevinlearynet / gist:10287914
Created April 9, 2014 16:15
MySQL query to delete 'wp_posts' rows and 'wp_postmeta' rows from a WordPress database
# Delete all posts with given post type
DELETE FROM wp_posts WHERE post_type = 'shop_order';
# Delete all orphaned post_meta
DELETE wp_postmeta FROM wp_postmeta
WHERE NOT EXISTS (
SELECT * FROM wp_posts
WHERE wp_postmeta.post_id = wp_posts.ID
);
@Kevinlearynet
Kevinlearynet / largest-tables-in-mysql-database.sql
Last active November 8, 2022 06:49
Find the largest (sized by MB) tables in your MySQL database. Especially useful for diagnosing and fixing a bloated WordPress database.
# Find the largest tables in your MySQL database
SELECT
table_name as "Table",
table_rows as "Rows",
data_length as "Length",
index_length as "Index",
round(((data_length + index_length) / 1024 / 1024),2) as "Size (mb)"
FROM information_schema.TABLES
WHERE table_schema = "%%YOURDATABASE%%"
ORDER BY `Size (mb)` DESC
@Kevinlearynet
Kevinlearynet / gist:b4203d09e7a8d605725e
Created May 21, 2014 17:30
Faster admin-ajax.php for WordPress AJAX actions
<?php
define('DOING_AJAX', true);
if ( ! isset( $_POST['action'] ) )
die('-1');
require_once('../../../../wp-load.php');
// headers for JSON
header('Content-Type: application/json');
@Kevinlearynet
Kevinlearynet / auth0-migration.php
Created July 8, 2014 14:28
WP Admin page to assist with a migration of users to Auth0 authentication and login
/**
* Auth0 Migration: Admin Page
*
* Provide a UI in the WP admin for migrating users to Auth0
*/
public function auth0_admin_page() {
// requires admin privledges
if ( current_user_can('manage_options') ) {
@Kevinlearynet
Kevinlearynet / solr.js
Created December 17, 2014 17:41
Example of using 'solr-client' in Node.js environment
// install solr client package: `npm install solr --save`
var solr = require( 'solr-client' );
// client connects to solr host
var client = solr.createClient({
host : host,
port : port,
core : core,
path : path,
agent : agent,
@Kevinlearynet
Kevinlearynet / _elements.html
Last active August 29, 2015 14:15
Static Site Engines with Node + Express Code Samples
# Elements
Fundamental building blocks of MIT Technology Review's digital styles.
## Doctype
{{ organization }} makes use of certain HTML elements and CSS properties that require the use of the HTML5 doctype. Include it at the beginning of all your projects.
### HTML
```html
<!DOCTYPE html>
<html lang="en">
@Kevinlearynet
Kevinlearynet / controller.js
Last active August 29, 2015 14:20
Hapi.js plugin to autoversion files based on when they last changed: `/file.js?v={mtime_timestamp}`
/**
* DFP Test Page Controller
*
* This pulls in the data we need to output
* a story URL
*
* @pattern /dfp/
*/
'use strict';
@Kevinlearynet
Kevinlearynet / gist:6f25c676f257b9acad79
Created May 7, 2015 16:09
Hapi's prerequisite methods
/**
* /in/profile/edit
*/
'edit': {
auth: {
mode: "try",
strategy: global.__config.cookie.strategy
},
plugins: {
"hapi-auth-cookie": {
.navbar__mobile-search__close {
display: none;
@include mq($nav-02) {
@include input-default;
display: block;
@include absolute(20px 20px n n);
@include size(20px);
background: #fff;
@Kevinlearynet
Kevinlearynet / popular
Created January 19, 2016 15:04
QZ.com popular posts object, same as our /entries