Skip to content

Instantly share code, notes, and snippets.

View davidisnotnull's full-sized avatar
🛠️
On contract

David Johnson davidisnotnull

🛠️
On contract
View GitHub Profile
@davidisnotnull
davidisnotnull / ajax-queue.js
Created May 23, 2018 10:45
Queue ajax requests in Javascript
$(function() {
var initialLoad = 0;
var AjaxRequestsCompleted = (function() {
var numRequestToComplete,
requestsCompleted,
callBacks;
return function(options) {
if (!options) options = {};
@davidisnotnull
davidisnotnull / SessionHandler.cs
Created May 23, 2018 10:47
Custom Session Handler in .NET
using System;
using System.Web;
using System.Web.SessionState;
using System.Collections;
using System.Threading;
using System.Web.Configuration;
using System.Configuration;
namespace SampleProject.Mvc.Utilities
{
@davidisnotnull
davidisnotnull / base64-codec.js
Created May 23, 2018 10:48
Base64 codec in Javascript
var Base64 = {
// private property
_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
// public method for encoding
encode : function (input) {
var output = "";
var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
var i = 0;
@davidisnotnull
davidisnotnull / ValidationMessageExtension.cs
Created May 23, 2018 10:49
MVC Validation Message Extension
// This class allows for HTML to be used in ValidationResult error messages within
// the ViewModel. You call it using CustomValidationMessageFor(m => m.Property)
public static class ValidationMessageExtensions
{
public static IHtmlString CustomValidationMessageFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> ex)
{
var htmlAttributes = new RouteValueDictionary();
string validationMessage = null;
var expression = ExpressionHelper.GetExpressionText(ex);
@davidisnotnull
davidisnotnull / ValidationExample.cs
Created May 23, 2018 10:51
MVC ViewModel Validation
// Ensure that that ViewModel class inherits IValidatableObject, otherwise
// nought is gonna happen.
public class ViewModel : IValidatableObject
{
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
<configuration>
<packageSources>
<add key="Local References" value=".\References\" />
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
<add key="Microsoft" value="https://www.nuget.org/api/v2/curated-feeds/microsoftdotnet/" />
<add key="EPiServer" value="http://nuget.episerver.com/feed/packages.svc/" />
</packageSources>
</configuration>
@davidisnotnull
davidisnotnull / git-commands.txt
Last active April 10, 2020 13:21
Useful Git Commands
# Stages all uncommited files to local
git add -A
# Adds a commit message to the local staged files
git commit -m "Commit message"
# Pushes the locally staged files to the remote repo
git push origin
# Cleans up local branches from the remote
@davidisnotnull
davidisnotnull / powershell.txt
Last active July 31, 2018 13:15
Useful Powershell commands
Get-Hotfix - lists all of the updates (KB######) that have been applied to the server
@davidisnotnull
davidisnotnull / regex.txt
Created July 18, 2018 10:06
All manner of Regex
Regex for field that allows numbers and spaces
[0-9 ]+
@davidisnotnull
davidisnotnull / redirect.config
Last active May 9, 2019 13:39
Example redirects and rewrite rules
<?xml version="1.0" encoding="utf-8"?>
<rewrite>
<rules>
<rule name="RedirectRule">
<match url="^redirect-url/(.*)" ignoreCase="true" />
<action type="Redirect" url="/test/my-actual-url/" redirectType="Permanent" />
</rule>
<rule name="RewriteRule">
<match url="^my-new-url/(.*)$" ignoreCase="true" />
<action type="Rewrite" url="Location/On/Server/{R:1}" />