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 / 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.

@scottoffen
scottoffen / Program.cs
Created August 30, 2019 17:35
Make delegates from methods
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Linq;
namespace DelegateTesting
{
public class Program
{
public static void Main(string[] args)
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
{
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 January 31, 2019 22:49
Rename files downloaded from Packt via LinqPad
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 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 / 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 / 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-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() {}