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 / nav-wizard.bootstrap.css
Last active March 5, 2017 22:30
Wizard style navigation tabs for bootstrap
.nav-pills.nav-wizard > li {
position: relative;
overflow: visible;
border-right: 15px solid transparent;
border-left: 15px solid transparent;
}
.nav-pills.nav-wizard > li + li {
margin-left: 0;
}
.nav-pills.nav-wizard > li:first-child {
@bjcull
bjcull / AuthorizeRedirect.cs
Last active September 27, 2015 13:33
Authorize attribute that redirects to view if you're logged in but don't have permission
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
public class AuthorizeRedirect : AuthorizeAttribute
{
public string RedirectUrl = "~/Error/Unauthorized";
protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
{
base.HandleUnauthorizedRequest(filterContext);
if (filterContext.RequestContext.HttpContext.User.Identity.IsAuthenticated)
@bjcull
bjcull / BaseController.cs
Created July 14, 2014 04:29
Return ModelState errors gracefully to an AJAX request
protected ActionResult JsonFormResponse(JsonRequestBehavior jsonRequestBehaviour = JsonRequestBehavior.DenyGet)
{
if (ModelState.IsValid)
{
return new HttpStatusCodeResult(200);
}
var errorList = new List<JsonValidationError>();
foreach (var key in ModelState.Keys)
{
@bjcull
bjcull / bootstrapSwitch.js
Created July 24, 2014 06:04
Angular directive for bootstrap-switch | http://www.bootstrap-switch.org/
.directive('bootstrapSwitch', [
function() {
return {
restrict: 'A',
require: '?ngModel',
link: function(scope, element, attrs, ngModel) {
element.bootstrapSwitch();
element.on('switchChange.bootstrapSwitch', function(event, state) {
if (ngModel) {
@bjcull
bjcull / AutoHotKey.ahk
Last active August 29, 2015 14:07
Key remapping for running windows on a mac. AutoHotKey on Windows side, Karabiner on Mac side.
; The below line is for debugging key presses in the key history.
; #InstallKeybdHook
; Turn my useless right alt key into a rad delete key
RAlt::Delete
; Capture the custom remapped playback keys from the mac keyboard remapper
<+<^F7::Send,{Media_Prev}
<+<^F8::Send,{Media_Play_Pause}
<+<^F9::Send,{Media_Next}
@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 / 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 / ChartDraw.html
Created May 23, 2015 22:11
A prototype graph with user drawn lines over the top
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
</head>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.2/Chart.min.js"></script>
@bjcull
bjcull / loading-button.js
Created July 8, 2015 13:16
An angular directive for the Ladda loading button. (Requires the jquery ladda plugin).
.directive('loadingButton', [
'$compile', function($compile) {
return {
restrict: 'A',
link: function(scope, element, attr) {
/* attr.style == "data-style" */
if (attr.loadingButtonAnimation && !attr.style) {
element.attr("data-style", attr.loadingButtonAnimation);
} else if (!attr.loadingButtonAnimation && !attr.style) {
element.attr("data-style", "slide-left");
@bjcull
bjcull / ActiveRouteTagHelper.cs
Last active June 8, 2018 12:14 — forked from anonymous/ActiveRouteTagHelper.cs
Adds an "active" class to the given element when the route parameters match. An Active Route Tag Helper.
[HtmlTargetElement(Attributes = "is-active-route")]
public class ActiveRouteTagHelper : TagHelper
{
private IDictionary<string, string> _routeValues;
/// <summary>The name of the action method.</summary>
/// <remarks>Must be <c>null</c> if <see cref="P:Microsoft.AspNetCore.Mvc.TagHelpers.AnchorTagHelper.Route" /> is non-<c>null</c>.</remarks>
[HtmlAttributeName("asp-action")]
public string Action { get; set; }