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
scottoffen / .gitconfig
Created Jun 14, 2019
Sample Git Configuration File
View .gitconfig
[user]
name = [Your Name]
email = [Your Work Email Address]
[alias]
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
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
scottoffen / README.md
Created Oct 21, 2018
Fixing the NOBLOGREDIRECT problem
View README.md

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 Mar 6, 2018
PHP Image Gallery using Bootstrap 4
View README.md

work in progress

using bootstrap 4, importing fontawesome but not using it yet

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

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 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
scottoffen / grapevine-register-singleton.md
Created Jun 7, 2017
Grapevine: Manual Registration of a Singleton
View grapevine-register-singleton.md

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 Jun 3, 2017
Grapevine: Adding Parameters To Routes
View grapevine-route-params.md

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"]);
}
You can’t perform that action at this time.