Skip to content

Instantly share code, notes, and snippets.

View scottoffen's full-sized avatar
💭
Live in SLC

Scott Offen scottoffen

💭
Live in SLC
View GitHub Profile
@scottoffen
scottoffen / README.md
Created October 21, 2018 05:10
Fixing the NOBLOGREDIRECT problem

Using the line define('NOBLOGREDIRECT', '%siteurl%'); in your wp-config.php makes it so that when someone enters a subdomain that does not exist on your site, it will redirect to whatever url you specify. You can use this to have it either go to a specific FAQ page or directly back to the main root installation, anywhere you want to direct it. the variable %siteurl% can be replaced; for example define('NOBLOGREDIRECT', 'http://frumph.net/FAQ/site-create');

When someone in their browser tries to go to a subdomain that doesn't exist (for example, http://badsubdomain.frumph.net/), they will be redirected to what is defined for NOBLOGREDIRECT.

Without using NOBLOGREDIRECT the (for example) http://badsubdomain.frumph.net/ – which is a subdomain that doesn't exist would direct to the signup page asking which reports whether or not the user can create the bad subdomain in question. This is fine, there's nothing wrong with it redirecting to the signup page if someone put in a bad url. However, those of

@scottoffen
scottoffen / README.md
Last active March 6, 2018 23:07
PHP Image Gallery using Bootstrap 4

work in progress

using bootstrap 4, importing fontawesome but not using it yet

@scottoffen
scottoffen / grapevine-custom-logger.md
Last active May 29, 2018 17:04
Customizing The Grapevine Logger

Customizing The Grapevine 4 Logger

First, create a class that implements the IGrapevineLogger interface.

public class MyCustomLogger : IGrapevineLogger
{
    // implementation details
}
@scottoffen
scottoffen / grapevine-input-validation.cs
Last active July 28, 2017 15:05
Grapevine: Input validation
// the context will be passed into the method automatically by the router
server.Router.BeforeRouting += context =>
{
// Do your input validation here
if (!context.Request.Payload.Contains("elephant"))
{
// by sending a response to the request, no additional processing will occur.
context.Response.SendResponse(HttpStatusCode.BadRequest, "no elephants allowed");
}
@scottoffen
scottoffen / grapevine-register-singleton.md
Created June 7, 2017 16:37
Grapevine: Manual Registration of a Singleton

Create the class that manages the list of APIs as a singleton.

public class ApiKeyManager
{
    private static ApiKeyManager _instance;
    public readonly List<string> ApiKeys = new List<string>();

    private ApiKeyManager() {}
@scottoffen
scottoffen / grapevine-route-params.md
Last active June 3, 2017 18:28
Grapevine: Adding Parameters To Routes

To set up a route that parses parameters from the path info:

[RestRoute(HttpMethod = HttpMethod.GET, PathInfo = "/cars/[carId]")]
public IHttpContext GetCarById(IHttpContext context)
{
	// Get the car id from the incoming context:
	Console.WriteLine(context.Request.PathParameters["carId"]);
}
@scottoffen
scottoffen / open-cover-xunit.bat
Created July 25, 2016 00:56
Original implementation of OpenCover and Xunit on the Grapevine project
@ECHO OFF
REM OpenCover-xunit.bat
REM Run opencover against xunit tests in your test project and show report of code coverage
Set SearchDirectory=%~dp0Grapevine.Tests\bin\Debug
SET DllContainingTests=%~dp0Grapevine.Tests\bin\Debug\Grapevine.Tests.dll
REM *** IMPORTANT - Change DllContainingTests variable (above) to point to the DLL
@scottoffen
scottoffen / .gitconfig
Last active March 7, 2016 16:05
Git Personal
[alias]
personal = config user.email "personal@emailaddress.com"
@scottoffen
scottoffen / xml-element-order.md
Created December 22, 2015 17:23
XML Element Ordering

XML Element Ordering

TL;DR

If your XSD is using the xs:sequence indicator, then the order of the elements in that complex type matters, and they should be included in the order listed inside the tag.

XML Specification

Generally speaking, the order in which child elements appear inside their parent element container in XML shouldn't matter. As such, the following two examples would be considered semantically equivalent XML.

Using NTLM in Node.js

Add a project dependency for express-ntlm. In your express configuration, require in this package.

var app = require('express');
var ntlm = require('express-ntlm');

Just before adding routes to the app (after all the body parsing and static references, etc.):