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 / 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 / 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}
/****** Object: UserDefinedFunction [dbo].[SplitQuoteSafe] Script Date: 09/13/2010 16:57:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- SELECT * FROM dbo.SplitQuoteSafe('"Test","Stuff, that, has commas","ok",24.45,,yes', ',')
CREATE FUNCTION [dbo].[SplitQuoteSafe]
(
@RowData nvarchar(2000),
@SplitOn nvarchar(5)
@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 / ContinuumTransition.cs
Created November 7, 2011 14:25
Continuum Transition for Silverlight Toolkit
namespace BenjiiMe.Animation
{
public class ContinuumTransition : TransitionElement
{
public const string ContinuumElementPropertyName = "ContinuumElement";
public const string ContinuumModePropertyName = "Mode";
public FrameworkElement ContinuumElement
{
get { return (FrameworkElement)GetValue(ContinuumElementProperty); }
@bjcull
bjcull / PropertyNotify.snippet
Created September 16, 2012 04:06
Property with NotifyOfPropertyChange Code Snippet. To be used with the Caliburn.Mircro library.
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets
xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Property with Notify Snippet</Title>
<Author>Ben Cull - http://benjii.me</Author>
<Description>Inserts a full property with a NotifyOfPropertyChange statement as well. To be used with the Caliburn.Mircro library.</Description>
<Shortcut>propnfy</Shortcut>
</Header>
@bjcull
bjcull / QuickEvent.js
Created February 17, 2013 04:34
A tiny javascript event engine
var QuickEvent = function () {
var nextSubscriberId = 0;
var subscriberList = [];
var subscribe = function (callback) {
var id = nextSubscriberId;
subscriberList[id] = callback;
nextSubscriberId++;
return id;
};
@bjcull
bjcull / HttpsWebServiceHostFactory.cs
Created September 12, 2013 01:07
Dynamically creates https endpoints for Configurationless WCF (Restful)
public class HttpsWebServiceHostFactory : WebServiceHostFactory
{
protected override System.ServiceModel.ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
{
WebServiceHost host = new WebServiceHost(serviceType, baseAddresses);
foreach (Uri baseAddress in baseAddresses)
{
WebHttpBinding binding = CreateRestBinding(baseAddress);
ServiceEndpoint endpoint = host.AddServiceEndpoint(serviceType.GetInterfaces()[0], binding, baseAddress);
@bjcull
bjcull / HttpsServiceHostFactory.cs
Created September 12, 2013 01:06
Dynamically create https endpoints for configurationless WCF
public class HttpsServiceHostFactory : ServiceHostFactory
{
protected override System.ServiceModel.ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
{
ServiceHost host = new ServiceHost(serviceType, baseAddresses);
foreach (Uri baseAddress in baseAddresses)
{
BasicHttpBinding binding = CreateSoapBinding(baseAddress);
@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) {