Skip to content

Instantly share code, notes, and snippets.

View bjcull's full-sized avatar
💲
Helping people get paid

Ben Cull bjcull

💲
Helping people get paid
View GitHub Profile
@bjcull
bjcull / CreditCardAttribute.cs
Created November 4, 2010 03:04
Credit Card Validator Attribute for ASP.NET MVC 3
/// ASP.NET MVC 3 Credit Card Validator Attribute
/// by Ben Cull - 4 November 2010
///
/// With special thanks to:
/// Thomas @ Orb of Knowledge - http://orb-of-knowledge.blogspot.com/2009/08/extremely-fast-luhn-function-for-c.html
/// For the Extremely fast Luhn algorithm implementation
///
/// And Paul Ingles - http://www.codeproject.com/KB/validation/creditcardvalidator.aspx
/// For a timeless blog post on credit card validation
@bjcull
bjcull / Install-Seq.ps1
Last active June 21, 2023 06:00 — forked from dennisroche/Install-Seq.ps1
Download and install Seq (https://getseq.net/). Can be used by Azure Resource Manager template. Use RawGit to access the file with proper Content-Type headers - https://rawgit.com/
[CmdletBinding()]
param (
[string]$SeqVersion,
[string]$SeqPort
)
$installBasePath = "C:\Install\"
$global:seqDataPath = "C:\ProgramData\Seq"
function Write-Log
@bjcull
bjcull / TimeService.cs
Created November 27, 2017 09:00
The current time service I use to keep track of dates relative to a certain timezone.
public class TimeService : ITimeService
{
private readonly ILogger _logger;
private Instant? _frozenTime;
private Instant _realTimeAtTimeOfFreezing = Instant.MinValue;
private readonly IDateTimeZoneProvider _timeZoneProvider = DateTimeZoneProviders.Tzdb;
private readonly DateTimeZone _timeZone;
public TimeService(ILogger logger, string systemTimeZone, DateTime? setDate = null)
@bjcull
bjcull / ExcelExtensions.cs
Created December 21, 2011 03:22
Export an IEnumerable to Excel
public static class ExcelExtensions
{
public static FileStreamResult ToDownloadableXmlFileForExcel2003(this System.Xml.Linq.XDocument file, string fileName)
{
MemoryStream ms = new MemoryStream();
file.Save(ms); //.Save() adds the <xml /> header tag!
ms.Seek(0, SeekOrigin.Begin);
var r = new FileStreamResult(ms, "application/vnd.ms-excel");
@bjcull
bjcull / CustomRequireHttpsFilter.cs
Created May 15, 2015 06:50
An improved HTTPS redirection filter for ASP.NET MVC.
public class CustomRequireHttpsFilter : RequireHttpsAttribute
{
protected override void HandleNonHttpsRequest(AuthorizationContext filterContext)
{
// The base only redirects GET, but we added HEAD as well. This avoids exceptions for bots crawling using HEAD.
// The other requests will throw an exception to ensure the correct verbs are used.
// We fall back to the base method as the mvc exceptions are marked as internal.
if (!String.Equals(filterContext.HttpContext.Request.HttpMethod, "GET", StringComparison.OrdinalIgnoreCase)
&& !String.Equals(filterContext.HttpContext.Request.HttpMethod, "HEAD", StringComparison.OrdinalIgnoreCase))
@bjcull
bjcull / mr-leesy.xml
Created August 19, 2019 02:33
Mr Leesy - BeerXML Recipe
<?xml version="1.0" encoding="UTF-8"?>
<RECIPES>
<RECIPE>
<NAME>Mr Leesy</NAME>
<STYLE>
<STYLE_GUIDE>BJCP</STYLE_GUIDE>
<VERSION>1</VERSION>
<NAME>American IPA</NAME>
<STYLE_LETTER>B</STYLE_LETTER>
<CATEGORY_NUMBER>14</CATEGORY_NUMBER>
@bjcull
bjcull / white-rabbit-dark-ale-148190.xml
Created August 19, 2019 02:14
White Rabbit Dark Ale - Clone Recipe
<?xml version="1.0" encoding="UTF-8"?>
<RECIPES>
<RECIPE>
<NAME>White Rabbit Dark Ale</NAME>
<STYLE>
<STYLE_GUIDE>BJCP</STYLE_GUIDE>
<VERSION>1</VERSION>
<NAME>Northern English Brown Ale</NAME>
<STYLE_LETTER>C</STYLE_LETTER>
<CATEGORY_NUMBER>11</CATEGORY_NUMBER>
@bjcull
bjcull / SubdomainRoute.cs
Created February 18, 2015 10:22
A class to detect the subdomain and pass it through as a route parameter
public class SubdomainRoute : RouteBase
{
public override RouteData GetRouteData(HttpContextBase httpContext)
{
if (httpContext.Request == null || httpContext.Request.Url == null)
{
return null;
}
var host = httpContext.Request.Url.Host;
@bjcull
bjcull / paymentsInProcess.qry
Created March 29, 2019 04:32
SQL Output for my perhaps not so efficient query
DECLARE @__submerchantId_0 int = 147;
DECLARE @__startDateLocal_Value_1 datetime2(7) = '2019-01-25';
DECLARE @__endDateLocal_Value_2 datetime2(7) = '2019-03-29';
DECLARE @__p_3 int = 0;
DECLARE @__p_4 int = 50;
SELECT [x.Payer].[Id], [x.Payer].[AssemblyBuyerId], [x.Payer].[CreatedTimeUtc], [x.Payer].[DisplayId], [x.Payer].[EmailAddress], [x.Payer].[FirstName], [x.Payer].[ImportSource], [x.Payer].[ImportSourceReference], [x.Payer].[IsDeleted], [x.Payer].[LastName], [x.Payer].[MobileNumber], [x.Payer].[Postcode], [x.Payer].[StreetAddress], [x.Payer].[SubMerchantId], [x.Payer].[Suburb], [x].[DisplayId] AS [Id0],
(
SELECT TOP(1) [y3].[Status]
FROM [Attempts] AS [y3]
@bjcull
bjcull / WordDocumentAttribute.cs
Created January 30, 2014 03:52
A Filter Attribute that lets you download an ASP.NET MVC View as a Word Document
public class WordDocumentAttribute : ActionFilterAttribute
{
public string DefaultFilename { get; set; }
public override void OnActionExecuted(ActionExecutedContext filterContext)
{
var result = filterContext.Result as ViewResult;
if (result != null)
result.MasterName = "~/Views/Shared/_LayoutWord.cshtml";