Skip to content

Instantly share code, notes, and snippets.

Scott Offen scottoffen

Block or report user

Report or block scottoffen

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
scottoffen / .gitconfig
Created Jun 14, 2019
Sample Git Configuration File
View .gitconfig
name = [Your Name]
email = [Your Work Email Address]
unstage = reset HEAD
co = checkout
ci = commit -m
s = status
com = checkout master
pr = git remote prune origin
View HeaderCollection.cs
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Runtime.Serialization;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
namespace Sandbox
View ParagraphBuilder.cs
public class ParagraphBuilder
public const int DefaultColumns = 86;
private string _input;
private int _columns;
private int _remaining;
private List<string> _output = new List<string>();
private List<string> _line = new List<string>();
scottoffen / Rename.cs
Created Jan 31, 2019
Rename files downloaded from Packt via LinqPad
View Rename.cs
void Main()
var dir = @"Y:\Downloads\My Books\";
var filepaths = Directory.GetFiles(dir, "*.pdf", SearchOption.TopDirectoryOnly);
var pattern = @"^\d{13}\-(\w+)\.pdf$";
var regex = new Regex(pattern);
foreach (var filepath in filepaths)
var filename = Path.GetFileName(filepath);
scottoffen /
Created Oct 21, 2018
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', '');

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

Without using NOBLOGREDIRECT the (for example) – 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 /
Last active Mar 6, 2018
PHP Image Gallery using Bootstrap 4

work in progress

using bootstrap 4, importing fontawesome but not using it yet

scottoffen /
Last active May 29, 2018
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 / grapevine-input-validation.cs
Last active Jul 28, 2017
Grapevine: Input validation
View grapevine-input-validation.cs
// 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 /
Created Jun 7, 2017
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 /
Last active Jun 3, 2017
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:
You can’t perform that action at this time.