Skip to content

Instantly share code, notes, and snippets.

View ericmann's full-sized avatar
⚒️
Creating ...

Eric Mann ericmann

⚒️
Creating ...
View GitHub Profile
void this_is_a_subroutine( $args ) {
if ( check )
return;
do_something();
do_something_else();
if ( check )
return;
@ericmann
ericmann / gist:2784237
Created May 24, 2012 21:05
Consolidating my Websites

When WordPress first rolled in multisite features, I was thrilled. I immediately activated them and merged the two sites I already had - my personal portfolio and my business blog. At the time, I also had to have a "parent network" site ... so it really became three sites:

  • eamann.com (my primary domain and network parent)
  • work.eamann.com (my portfolio)
  • mindsharestrategy.com (mapped domain for my business blog)

Over time, my business blog evolved to contain a whole slew of other content - articles on faith, the outdoors, creative writing, etc. I added a couple of new mapped domains to my network and branched the content out to keep things separate:

  • prosepainting.com (creative writing)
  • groundedchristianity.com (faith essays)
@ericmann
ericmann / gist:2876388
Created June 5, 2012 17:26
"Phone app" template from WordCamp Phoenix presentation
<?php
/*
Template Name: RPC Test
*/
/**
* This template interacts with a new XML-RPC endpoint created specifically to handle `wcphx.change_query`
* Code for the endpoint is available in a ZIP file at: http://eam.me/3-
* Slides from the WordCamp Phoenix presentation are at: http://www.slideshare.net/ericmann/playing-nice-with-others-11758893
* Video from the presentation is at: http://wordpress.tv/2012/06/04/eric-mann-playing-nice-with-others-integrating-wp-with-other-apis/
// How can I rewrite this to perform multiple checks in a row without repeating if (_allowed.IPs.Contains(userIPAddress)) { authentic = true; goto result; } every time?
public class Authentication {
private List<string> _allowedIPs;
public bool IsAuthentic(string userIPAddress) {
bool authentic = false;
if (_allowedIPs == null)
_allowedIPs = new List<string>();
@ericmann
ericmann / gist:3005609
Created June 27, 2012 17:38
Authentication System

##The Scenario

I have a client-side web application that bounces requests against a server-side API. For the sake of simplicity, every request must pass a username and password. This is similar to old school XML-RPC where the username and password are passed as parameters in every request.

However, as this is a REST service, some of the requests (GET and DELETE) don't have message bodies and must pass the username and password as query variables in the URL:

GET http://application.url/endpoint?username=xxxx&password=xxxx

This is, frankly, a bad idea. Requests are logged on the server, so if I send the password in plaintext, it's now sitting in a log file somewhere on the server. I don't ever want to be sending the password in plaintext over the wire, so I'm stuck with a dilemma.

@ericmann
ericmann / gist:3130115
Created July 17, 2012 15:31
Sunrise if we architect to use a singleton
<?php
/**
* Here's the Sunrise class demonstrating how it would be used as a singleton.
* NOTE: Code is for discussion only and has not been tested.
*/
class Sunrise {
static private $instance = null;
static public function get_instance() {
if ( ! isset( self::$instance ) ) {
// the upload image button, saves the id and outputs a preview of the image
$('.meta_box_upload_image_button').click(function() {
formID = $(this).attr('rel');
formfield = $(this).siblings('.meta_box_upload_image');
preview = $(this).siblings('.meta_box_preview_image');
tb_show('Choose Image', 'media-upload.php?post_id='+formID+'&type=image&custom=simple&TB_iframe=1');
window.orig_send_to_editor = window.send_to_editor;
window.send_to_editor = function(html) {
img = $('img',html);
imgurl = img.attr('src');
<?xml version="1.0" encoding="UTF-8"?> <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" ><channel><title>Zooming Japan &#187; Blog</title> <atom:link href="http://zoomingjapan.com/blog/feed/" rel="self" type="application/rss+xml" /><link>http://zoomingjapan.com</link> <description></description> <lastBuildDate>Wed, 10 Oct 2012 15:03:55 +0000</lastBuildDate> <language>en-US</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <item><title>Akita: Kakunodate</title><link>http://zoomingjapan.com/travel/akita-kakunodate/</link> <comments>http://zoomingjapan.com/travel/akita-kakunodate/#comments</comments> <pubDate>Wed, 10 Oct 2012 15:03:55 +0000</pubDate> <dc:creator>zoomingjapan</dc:creator> <category><![C
@ericmann
ericmann / gist:4028438
Created November 6, 2012 23:25
Endpoint registration
function my_init() {
add_rewrite_endpoint( 'my_entry', EP_ALL );
add_rewrite_endpoint( 'my_booked', EP_ALL );
add_rewrite_endpoint( 'my_custom_css', EP_ALL );
}
/**
* Flush rewrite rules on plugin activation.
*/
@ericmann
ericmann / robot.js
Created December 3, 2012 16:46
Test Bot
//FightCode can only understand your robot
//if its class is called Robot
var Robot = function(robot) {
};
Robot.prototype.onIdle = function(ev) {
var robot = ev.robot;
robot.ahead(100);