Skip to content

Instantly share code, notes, and snippets.

View EdHurtig's full-sized avatar

Ed Hurtig EdHurtig

View GitHub Profile
@EdHurtig
EdHurtig / apache-restart
Created March 20, 2013 03:04
Script to restart apache on a mac - you can find it elsewhere, I just have this copy
do shell script "apachectl graceful" with administrator privileges
@EdHurtig
EdHurtig / utilities.java
Created March 20, 2013 03:10
One of my early java utilities classes - it's a mess
import java.io.*;
public class Utilities {
public static String Version = "1.2";
/**
* --------------------------------------------------------- UTILITIES CLASS
* FOR JAVA PROGRAMMING @ LSRHS * AUTHOR: EDDIE HURTIG * SOME (c) MIKE
* MALONE * ------------------------------------------------------------
package { "sl":
ensure => "purged"
}
@EdHurtig
EdHurtig / network_get_post_meta.php
Created May 29, 2014 16:29
Add the ability to get post meta from the network_postmeta table without having to switch_to_blog or jump through hoops
<?php
/**
*
* Gets the post meta for a specific post from the post indexer table
*
* @param int|post $post The ID of the Post that you want the meta for
* @param string $key (optional) The meta key of the data you want
* @param bool $single (optional) Whether to return a single Value
* @param int|bool $blog_id The ID of the blog that the post is located on
@EdHurtig
EdHurtig / update_timezone_on_all_sites.php
Created July 14, 2014 20:07
Updates the timezone on all WordPress sites to the specified PHP timezone
<?php
$timezone = 'America/New_York';
$blogs = wp_get_sites();
foreach ($blogs as $blog) {
switch_to_blog($blog['blog_id']);
echo 'Currently: ' . get_option('timezone_string') . ' for blog ' . $blog['blog_id'] . '<br />';
echo (update_option('timezone_string', $timezone) ? 'Updated' : 'Did Not Update') . '<br /><br/>';
restore_current_blog();
}
<?php
/**
* Loops through all the blogs in the network switching blogs and calling the given function with a single site returned from wp_get_sites
*
*
* @param callable $lambda A function to execute for every single blog on the network
*/
function foreach_blog( $lambda ) {
$blogs = wp_get_sites( array( 'limit' => false ) );
foreach ( $blogs as $blog ) {
@EdHurtig
EdHurtig / foreach_post.php
Created July 14, 2014 20:14
A very shorthand way of looping through all the posts in your blog that rids you of all the clutter of WP_Query and get_posts
<?php
/**
* Allows you to loop through a simple posts query
* @example foreach_post( function () { wp_delete_post( $post->ID ); } );
*
* @example foreach_post( 'faq', function () { echo $post->post_title . '<br />' } );
* @example foreach_post( array( 'book', 'faq'), function () { echo $post->post_title; } );
* @example foreach_post( 'book,faq', function () { echo $post->post_title; } );
*
* @example foreach_post( false, false, function () { echo $post->post_title; } );
@EdHurtig
EdHurtig / StopWatch.java
Created November 20, 2014 16:15
A Simple Java Stopwatch Class
package jServe.Core;
/**
* A simple java stopwatch
*/
public class StopWatch {
/**
* Whether the stopwatch is running
*/
private boolean running;
@EdHurtig
EdHurtig / .bash_profile_kitchen.sh
Created January 22, 2015 16:06
Alters the `kitchen` command to easily provide a kitchen configuration to kitchen.
# Usage
# kitchen cloud test # Will run 'kitchen test' with 'KITCHEN_YAML=.kitchen.cloud.yml'
# kitchen local test # Will run 'kitchen test' with 'KITCHEN_YAML=.kitchen.local.yml'
# kitchen test # Will run 'kitchen test' without a KITCHEN_YAML specified
kitchen() {
if [[ 'cloud,local,dev,prod,stage' == *$1* ]]; then
echo "Starting kitchen with configuration file '.kitchen.$1.yml'"
if [[ -f ".kitchen.$1.yml" ]]; then
command export KITCHEN_YAML=.kitchen.cloud.yml
@EdHurtig
EdHurtig / aws_zombies.rb
Last active August 29, 2015 14:13
Searches AWS for zombie test servers
#!/usr/bin/env ruby
require 'aws-sdk'
require 'colorize'
AWS.config(
access_key_id: ENV['AWS_ACCESS_KEY_ID'],
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'])
if ARGV.any?
security_group = ARGV[0]