Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@lewayotte
lewayotte / NetworkOut.sh
Last active July 24, 2017 23:44
AWS Bandwidth Usage Report by Instance
#!/bin/bash
EC2_INSTANCE_ID="`wget -q -O - http://169.254.169.254/latest/meta-data/instance-id || die \"wget instance-id has failed: $?\"`"
test -n "$EC2_INSTANCE_ID" || die 'cannot obtain instance-id'
EC2_AVAIL_ZONE="`wget -q -O - http://169.254.169.254/latest/meta-data/placement/availability-zone || die \"wget availability-zone has failed: $?\"`"
test -n "$EC2_AVAIL_ZONE" || die 'cannot obtain availability-zone'
EC2_REGION="`echo \"$EC2_AVAIL_ZONE\" | sed -e 's:\([0-9][0-9]*\)[a-z]*\$:\\1:'`"
@lewayotte
lewayotte / subs_filters.txt
Last active March 26, 2017 02:53
Aggressive vs Non-Agressive subs_filters
#Aggressive
subs_filter //lewayotte.com/wp-content/ //d9ye22nzps5tq.cloudfront.net/wp-content/;
subs_filter //lewayotte.com/wp-includes/ //d9ye22nzps5tq.cloudfront.net/wp-includes/;
subs_filter \/\/lewayotte.com\/wp-content\/ \/\/d9ye22nzps5tq.cloudfront.net\/wp-content\/;
subs_filter \/\/lewayotte.com\/wp-includes\/ \/\/d9ye22nzps5tq.cloudfront.net\/wp-includes\/;
#Not So Aggressive (set exactly which extensions you want it to pass to the CDN)
subs_filter //lewayotte.com/wp-content/(.*)\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf|css|js) //d9ye22nzps5tq.cloudfront.net/wp-content/$1.$2 gir;
subs_filter //lewayotte.com/wp-includes/(.*)\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf|css|js) //d9ye22nzps5tq.cloudfront.net/wp-includes/$1.$2 gir;
subs_filter \/\/lewayotte.com\/wp-content\/(.*)\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|j
@lewayotte
lewayotte / jeopardy.ino
Created January 30, 2017 13:54
Arduino Jeopardy Buzzer Source Code
#include "musical_notes.h"
const int speakerPin = 3;
const int resetPin = 5;
const int player1 = 12;
const int player2 = 10;
const int player3 = 9;
const int pLight1 = 13;
const int pLight2 = 11;
const int pLight3 = 8;
@lewayotte
lewayotte / default-exclude.php
Created January 20, 2017 13:33
Exclude Twitter by default in Leenk Me
<?php
function default_exclude( $post ) {
global $hook_suffix;
if ( 'post-new.php' == $hook_suffix ) {
update_post_meta( $post->ID, '_twitter_exclude', true );
}
}
add_action( 'dbx_post_advanced', 'default_exclude' );
@lewayotte
lewayotte / reactionGame.ino
Last active November 10, 2016 16:12
Reaction Game for Arduino using LCD, LED, and Switch
#include <LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);
const int switchPin = 8;
int switchStatus = LOW;
const int ledPin = 7;
int time = 0;
bool startPhase1 = false;
int randomStart = 0;
bool startPhase2 = false;
bool gameComplete = false;
@lewayotte
lewayotte / leenkme-shortener.php
Created May 3, 2016 02:30
Example of using a URL shortener since leenk.me v2.10.0
<?php
/*
* Add this file to the wp-content/mu-plugins/ directory
*/
function my_leenkme_shortener( $permalink, $post_id) {
if ( $existing = get_post_meta( $post_id, '_leenkme_short_url', true ) ) {
$permalink = $existing;
@lewayotte
lewayotte / wcatl.php
Created March 14, 2016 04:57
SAAS REST API for WordPress
<?php
function wcatl_api() {
if ( !empty( $_GET['wcatl'] ) ) {
try {
$input = file_get_contents( 'php://input' );
$post = json_decode( $input, TRUE );
if ( !empty( $post['post-id'] ) ) {
error_log( sprintf( 'New Post Published %s', $post['post-id'] ) );
}
@lewayotte
lewayotte / wcatl-notify.php
Created March 14, 2016 04:50
Example Plugin to Send Data to SAAS Backend from WordPress
<?php
function wcatl2016_transition_post_status( $new_status, $old_status, $post ) {
$api_url = 'https://lewayotte.com/?wcatl=1';
if ( 'publish' === $new_status && 'publish' !== $old_status ) {
$args = array(
'headers' => array( 'content-type' => 'application/json' ),
'body' => json_encode( array( 'post-id' => $post->ID ) ),
);
$response = wp_remote_post( $api_url, $args );
@lewayotte
lewayotte / wcatl2016.php
Created March 14, 2016 02:17
Custom RESTful API for WCATL 2016
<?php
function wcatl2016_api() {
if ( !empty( $_GET['wcatl2016'] ) ) {
switch( strtolower( $_GET['wcatl2016'] ) ) {
case 'get-users':
$response = wcatl2016_api_get_users();
break;
case 'add-user':
$response = wcatl2016_api_create_user();
@lewayotte
lewayotte / wprobot-leenkme.php
Last active January 12, 2016 14:46
Delay WP Robot posts by 3 minutes for leenk.me's use
<?php
function setup_wprobot_filters_for_leenkme( $content, $title, $catarray ) {
add_filter( 'wp_insert_post_data', 'delay_wp_robot_posts_by_3_minutes_for_leenkme', 10, 2 );
}
add_action( 'wpr_before_post_save', 'setup_wprobot_filters_for_leenkme', 10, 3 );
function delay_wp_robot_posts_by_3_minutes_for_leenkme( $data, $postarr ) {
if ( 'publish' === $data['post_status'] ) {
$data['post_status'] = 'future';