Skip to content

Instantly share code, notes, and snippets.

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

Eric Mann ericmann

⚒️
Creating ...
View GitHub Profile
<?php
$one_off_filter = function( $text ) {
return str_replace( 'something', 'else', $text );
}
add_filter( 'the_content', $one_off_filter );
the_content();
remove_filter( 'the_content', $one_off_filter );
@ericmann
ericmann / wp-index-redis.php
Last active September 3, 2019 07:48
Alternative Index file for WordPress that uses Redis as a full-page cache.
<?php
/**
* WP Redix Index
*
* Redis caching system for WordPress. Inspired by Jim Westergren.
*
* @author Jeedo Aquino
* @see http://www.jeedo.net/lightning-fast-wordpress-with-nginx-redis/
* @see http://www.jimwestergren.com/wordpress-with-redis-as-a-frontend-cache/
*/
@ericmann
ericmann / default.conf
Created May 11, 2013 23:46
Default WordPress Nginx configuration file.
server {
listen 80;
server_name XX.XX.XX.XX;
root /var/www/html/default;
location / {
index index.php;
try_files $uri $uri/ /index.php?$args;
}
@ericmann
ericmann / default-cached.conf
Last active August 8, 2019 14:41
Redis-cached WordPress Nginx configuration file.
server {
listen 80;
server_name XX.XX.XX.XX;
root /var/www/html/default;
location /index.php {
alias /var/www/html/default/wp-index-redis.php;
}
location / {
@ericmann
ericmann / predis.php
Created May 11, 2013 23:59
Predis - a flexible Redis client for PHP
<?php
namespace Predis;
class PredisException extends \Exception { }
class ClientException extends PredisException { } // Client-side errors
class AbortedMultiExec extends PredisException { } // Aborted multi/exec
class ServerException extends PredisException { // Server-side errors
public function toResponseError() {
return new ResponseError($this->getMessage());
<?php
$post_ids = array( 1, 2, 3, 4 );
foreach ( $post_ids as $post_id ) {
$post = get_post( $post_id );
if ( null === $post ) {
continue;
}
@ericmann
ericmann / chandra.js
Last active December 17, 2015 14:38
JavaScript routine for modelling the internal structure of white dwarf stars and calculating the Chandrasekhar Limit.
( function( window, undefined ) {
var md, rd;
// Constants
var MU = 2.0;
G = 6.626 * Math.pow( 10, -8 ),
PI = 3.14159,
MS = 1.989 * Math.pow( 10, 33 ),
RS = 6.96 * Math.pow( 10, 10 ),
CSQ = Math.pow( 2.9979 * Math.pow( 10, 10 ), 2 );
@ericmann
ericmann / class-wp-cookie-ixr-client.php
Created June 18, 2013 20:05
Build an IXR_Client object that uses WordPress' built-in HTTP request layer as a transport, while still passing user cookies along with the request.
@ericmann
ericmann / gist:5949377
Last active December 19, 2015 11:39
Pseudo-singleton for WordPress.
<?php
class Example {
public function __construct() {
$this->instantiate();
}
public function instantiate() {
static $instance = null;
@ericmann
ericmann / gist:7702180
Last active December 29, 2015 17:09
Quicky PHPUnit accessiblity example.
<?php
/**
* This class contains two private methods we wish to test.
* In reality, it would also contain several public methods,
* but that's immaterial to our discussion.
*
* @package Tutorials
*/
class ClassToTest {
/**