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 / bulk-resize-script
Created March 26, 2014 00:57
Imagemagick recursively reduce files to < 800x600 and 72ppi
# This is a bash script meant to be run on the command line. Requires imagemagick (apt-get install imagemagick)
## THIS WILL OVERWRITE YOUR FILES, uses sudo and may not require it.
for file in /path/to/files/*/*.jpg; do sudo convert $file -resize '800x600>' -density 72 $file; done
### another method using resolution (800*600)
for file in /path/to/files/*/*.jpg; do sudo convert $file -resize '480000@>' -density 72 $file; done
### example of *not* overwriting files
for file in /path/to/files/*/*.jpg; do sudo convert $file -resize '800x600>' -density 72 converted-$file; done
@MikeNGarrett
MikeNGarrett / zendesk-ticket-export.php
Last active February 1, 2018 10:01
Zendesk ticket export for an organization without a premium account in PHP
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Money Morning Ticket Export</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script type="text/javascript">
jQuery(document).ready(function($) {
$('.ticket-util').click( function(e) {
e.preventDefault();
@MikeNGarrett
MikeNGarrett / wp-3-8-replace-open-sans
Last active January 10, 2018 14:39
WordPress 3.8 - replace admin Open Sans font with your own version
function replace_open_sans() {
// Kill the original style
wp_deregister_style('open-sans');
// Replace it with your own (just as an example, I included only the 300 weight)
wp_register_style( 'open-sans', 'http://fonts.googleapis.com/css?family=Open+Sans:300' );
wp_enqueue_style( 'open-sans');
}
add_action( 'wp_enqueue_scripts', 'replace_open_sans' );
// Thanks to @timkinnane
add_action( 'admin_enqueue_scripts', 'replace_open_sans' );
@MikeNGarrett
MikeNGarrett / utility.sh
Created December 13, 2017 21:11
Crawl a site to find 404, 301, 302, 500, etc responses
# Crawl a site's public urls to produce a csv list of urls and response codes
# This could be reduced into a single command, but I find it helpful to have a list of all urls.
# overview: crawl the site to add one url per line in a text file.
# NOTE: this must run and complete first.
# wget mirror's the site (including static files)
# grep files the line with the url on it.
# awk grabs the 3rd item (separated by spaces) and writes to urls.txt
wget --mirror -p https://domain.com/ 2>&1 | grep '^--' | awk '{ print $3 }' > urls.txt
<?php
/**
* This file will demonstrate a method to export fields to code.
* You can use this to easily create fields using the UI, export to code
* and then use in a custom module. Upon installation of the module
* your fields and instances will already be set up.
*/
// Create the fields you want using the Drupal UI.
// On the same site, go to example.com/devel/php
@MikeNGarrett
MikeNGarrett / devel-tool-export-field.php
Created October 10, 2017 16:23
Export a Drupal 7 field definition for use in custom modules.
<?php
// Found: https://steindom.com/articles/exporting-and-creating-field-definitions-drupal-7
// My new favorite developer because of this, "Now that you understand how it works, let me show you some easy tricks to incorporate this into your development workflow."
// Fill in these with your desired field details.
$entity_type = '';
$field_name = 'field_';
$bundle_name = '';
$info_config = field_info_field($field_name);
<?php
add_filter('the_content','add_my_content');
function add_my_content($content) {
$my_custom_text = '<hr><div class="patreonpara"><p><em>PARAGRAPH TEXT</em></p><a href="LINKURL" data-patreon-widget-type="become-patron-button" class="patreonbutton"><img src="FILEURL"></a></div>';
$my_custom_text_other = 'something else';
if(is_single() && !is_home()) {
if(in_category('videos')) {
$content .= $my_custom_text_other;
} else {
$content .= $my_custom_text;
@MikeNGarrett
MikeNGarrett / siege-ab.sh
Last active December 19, 2016 04:07
Load Testing Examples
# Siege attempts to recreate real traffic by using a CSV of urls to hit.
# This allows you to remove requests for assets, if you're running a CDN.
#
# c = concurrent users
# i = "like the internet would visit"
# b = benchmark (no delay needed)
# t = time
# f = file with urls 1 per line
siege -c100 -i -b -t120S -f urls.csv
@MikeNGarrett
MikeNGarrett / chmod-correct-files
Last active November 21, 2016 08:49
Change file permissions to 664, directory permissions to 775
// Run this from the command line.
// h/t: http://superuser.com/questions/91935/how-to-chmod-755-all-directories-but-no-file-recursively#answer-91966
// add read/execute to world, remove write
chmod -R u+rwX,g+rwX,o+rX-w path/
// remove read/write/execute from world
chmod -R u+rwX,g+rwX,o-rwX path/
@MikeNGarrett
MikeNGarrett / change-cpt-to-page.php
Last active October 20, 2016 15:10
If you need to switch a WordPress custom post type from post capability to page capability, do this.
<?php
/* This doesn't work and here's why not.
*
* The missing piece here has to do with rewrite rules.
* The registration process creates new rewrite rules during the process.
* This ensures the custom post type is set up appropriately.
* Modifying the url structure (which we're doing here) to hierarchical requires a change to the rewrite rules as well.
*
* The following is the first change you need to make. The rewrite change is not included here.
*/