Skip to content

Instantly share code, notes, and snippets.

Avatar

Christopher Davis chrisguitarguy

View GitHub Profile
@chrisguitarguy
chrisguitarguy / nginx.conf
Created February 22, 2018 16:22
How to proxy requests from nginx to an upstream backend. Could be use for Python or JavaScript (express) apps.
View nginx.conf
http {
# other stuff here
# The upstream backend server this can be named whatever you desire
# See http://nginx.org/en/docs/http/ngx_http_upstream_module.html
upstream backend {
# this is the actual hostname + port of the backend server
server backend:8080;
# how many keep alive connections to allow, only set this if you're going
# to specify the `Connection` header in the proxy below, nginx sets the
@chrisguitarguy
chrisguitarguy / comments-example.php
Created September 21, 2011 21:44
How to add custom fields to WordPress comments
View comments-example.php
<?php
/*
Plugin Name: Add Extra Comment Fields
Plugin URI: http://pmg.co/category/wordpress
Description: An example of how to add, save and edit extra comment fields in WordPress
Version: n/a
Author: Christopher Davis
Author URI: http://pmg.co/people/chris
License: MIT
*/
@chrisguitarguy
chrisguitarguy / wp-remove-dashboard.php
Created November 18, 2011 22:25
Remove all the default WordPress dashboard widgets.
View wp-remove-dashboard.php
<?php
/*
Plugin Name: Remove Dashboard Meta Boxes
Plugin URI: http://pmg.co/category/wordpress
Description: Removes the default dashboard widgets from the WordPress admin.
Author: Christopher Davis
Author URI: http://pmg.co/people/chris
License: GPL2
*/
@chrisguitarguy
chrisguitarguy / logs.py
Created December 19, 2011 16:44
A simple python script to email myself server logs. Meant to run as a cron job.
View logs.py
import argparse
import os
import smtplib
from email import Encoders
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email.Utils import formatdate
@chrisguitarguy
chrisguitarguy / big-xml.php
Created February 27, 2013 04:15
How to use a combination of XMLReader and SimpleXMLElement to parse large XML files in PHP.
View big-xml.php
<?php
/**
* an example of how to read huge XML files relatively quickly and efficiently
* using a few core PHP libraries.
*
*/
// Assume your file is very large, 140MB or somethig like that
$fn = __DIR__ . '/some_file.xml';
@chrisguitarguy
chrisguitarguy / default-author.php
Created July 2, 2012 20:07
Set a default author for posts on your WordPress site.
View default-author.php
<?php
/*
Plugin Name: Default Author
Plugin URI: http://pmg.co
Description: Set a default author for all posts and pages
Version: 1.0
Text Domain: default-author
Author: Christopher Davis
Author URI: http://christopherdavis.me
License: GPL2
@chrisguitarguy
chrisguitarguy / cpt-permalinks.php
Created October 10, 2011 17:28
How to add fields to the WordPress permalinks page
View cpt-permalinks.php
@chrisguitarguy
chrisguitarguy / remove-feeds.php
Created March 28, 2012 04:37
Remove all feeds from WordPress
View remove-feeds.php
<?php
/*
Plugin Name: Remove All Feeds [for WPSE33072]
Description: Remove all feeds from WordPress
Author: Christopher Davis
Author URI: http://christopherdavis.me
License: GPL2
*/
@chrisguitarguy
chrisguitarguy / mask-links.php
Created December 14, 2011 14:38
Mask external WordPress links behind a redirect.
View mask-links.php
@chrisguitarguy
chrisguitarguy / KeepValueListener.php
Created February 26, 2016 14:29
A way to keep original values around when a Symfony form is submitted with an empty value. Useful for password fields especially
View KeepValueListener.php
<?php
/**
* Copyright (c) 2016 PMG <https://www.pmg.com>
*
* License: MIT
*/
use Symfony\Component\PropertyAccess\PropertyAccess;
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
use Symfony\Component\Form\FormEvents;