Skip to content

Instantly share code, notes, and snippets.

View MikeNGarrett's full-sized avatar
🤘
Rocking this project.

Mike Garrett MikeNGarrett

🤘
Rocking this project.
View GitHub Profile
@MikeNGarrett
MikeNGarrett / wp-config.php
Last active April 24, 2024 10:11
All those damned wp-config constants you can never remember.
<?php
// PHP memory limit for this site
define( 'WP_MEMORY_LIMIT', '128M' );
define( 'WP_MAX_MEMORY_LIMIT', '256M' ); // Increase admin-side memory limit.
// Database
define( 'WP_ALLOW_REPAIR', true ); // Allow WordPress to automatically repair your database.
define( 'DO_NOT_UPGRADE_GLOBAL_TABLES', true ); // Don't make database upgrades on global tables (like users)
// Explicitely setting url
@MikeNGarrett
MikeNGarrett / siege
Last active April 3, 2024 03:49
Siege with JSON POST data
# Changed to use content-type flag instead of header: -H 'Content-Type: application/json'
siege -c50 -t60S --content-type "application/json" 'http://domain.com/path/to/json.php POST {"ids": ["1","2","3"]}'
@MikeNGarrett
MikeNGarrett / functions.php
Created October 13, 2017 20:11
Set cache headers on WordPress 404 pages.
<?php
/**
* Force cache headers on 404 pages and prevent WordPress from handling 404s.
*
* @param bool $preempt determines who handles 404s.
* @param obj $wp_query global query object.
*/
function change_404_headers( $preempt, $wp_query ) {
if ( ! is_admin() && ! is_robots() && count( $wp_query->posts ) < 1 ) {
header( 'Cache-Control: max-age=30000, must-revalidate' );
@MikeNGarrett
MikeNGarrett / index.html
Created February 28, 2023 16:49
Conditionally changing script src
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Test</title>
</head>
<body>
<script type="module">
const condition = window.location.host == 'apexofacircle.github.io';
;;
;; Domain: wrir.org
;; Exported: 2017-01-20 02:47:07
;;
;; This file is intended for use for informational and archival
;; purposes ONLY and MUST be edited before use on a production
;; DNS server. In particular, you must:
;; -- update the SOA record with the correct authoritative name server
;; -- update the SOA record with the contact e-mail address information
;; -- update the NS record(s) with the authoritative name servers for this domain.
@MikeNGarrett
MikeNGarrett / gist:9405070
Last active February 12, 2023 17:58
Insert new user administrator account into WordPress via the database
# Grabbed for reference from http://www.wpbeginner.com/wp-tutorials/how-to-add-an-admin-user-to-the-wordpress-database-via-mysql/
# Check the table prefix
# Check the user_id to make sure it is the next in sequence
# Replace my name and email to your own
# Username will be demo and the password will be 1234
INSERT INTO `wp_users` (`ID`, `user_login`, `user_pass`, `user_nicename`, `user_email`, `user_url`, `user_registered`, `user_activation_key`, `user_status`, `display_name`) VALUES ('4', 'mgarrett', MD5('1234'), 'Mike Garrett', 'test@yourdomain.com', '', '2011-06-07 00:00:00', '', '0', 'Mike Garrett');
INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, '4', 'wp_capabilities', 'a:1:{s:13:"administrator";b:1;}');
INSERT INTO `wp_usermeta` (`umeta_id`, `user_id`, `meta_key`, `meta_value`) VALUES (NULL, '4', 'wp_user_level', '10');
# Troubleshooting
@MikeNGarrett
MikeNGarrett / kbe.py
Created November 22, 2022 17:08
Export Keybase teams messages and download attachments
# Forked: https://git.zapashcanon.fr/zapashcanon/kbe/
#To export a chat from the ZorkInc team, run:
# ./kbe.py ZorkInc
# It will create a folder ZorkInc in which you'll find a JSON file containing raw logs, a .log file containing human-readable export of the chat. It'll also download all attachments of the chat and put them in that same folder.
# Note: defaults to "general" channel in your team. Change references to this channel below under "topic_name" (3).
#!/usr/bin/python3
import json
import sys
import os
@MikeNGarrett
MikeNGarrett / wp-config.php
Created October 14, 2017 01:56
Disable admin-ajax on the front-end of WordPress sites and cache the resulting 404.
<?php
if(
strpos( $_SERVER['HTTP_REFERER'], 'wp-admin' ) === false &&
strpos( $_SERVER['REQUEST_URI'], 'admin-ajax.php' ) !== false
) {
header( 'Cache-Control: max-age=30000, must-revalidate' );
header( 'Expires: ' . gmdate( 'D, d M Y H:i:s', strtotime( '+5000 minutes' ) ) . ' GMT' );
header( 'Last-Modified: ' . gmdate( 'D, d M Y H:i:s', strtotime( '-5000 minutes' ) ) . ' GMT' );
header( $_SERVER["SERVER_PROTOCOL"]." 404 Not Found" );
die;
@MikeNGarrett
MikeNGarrett / module.module.php
Last active November 2, 2022 10:04
Drupal curated autocomplete field
<?php
use Drupal\Core\Form\FormStateInterface;
function hook_field_widget_complete_entity_reference_autocomplete_form_alter(&$field_widget_complete_form, $form_state, $context)
{
if($field_widget_complete_form['widget']['#field_name'] !== 'field_test') {
return;
}
$storage = Drupal::getContainer()->get('entity_type.manager')->getStorage('node');
@MikeNGarrett
MikeNGarrett / mysql(wp)-commands.txt
Created October 31, 2022 16:48 — forked from vishalkakadiya/mysql(wp)-commands.txt
WordPress(or any mysql database) - Convert special characters(eg. Latin-1) to UTF-8 in mysql database
The actual step-by-step WordPress / MySQL fix…
1. Back up all your stuff first (likely using phpMyAdmin / CPANEL)
Before doing any of the following it strongly encouraged to back up all your data and files. Just to be safe. At the very least, your full database and the WordPress config file: wp-config.php
2. Note the settings that your WordPress is currently using (from wp-config.php)
Specifically, your MySQL database configuration, including DB_NAME, DB_USER, DB_PASSWORD, and also DB_CHARSET and DB_COLLATE
// ** MySQL settings - You can get this info from your web host ** //