Skip to content

Instantly share code, notes, and snippets.

View brendankowitz's full-sized avatar

Brendan Kowitz brendankowitz

View GitHub Profile
@brendankowitz
brendankowitz / gist:4071660
Created November 14, 2012 11:36
Umbraco IHttpModule to switch to an optional [TemplateAlias]Mobile template when mobile devices are detected
using System;
using System.Linq;
using System.Web;
using Kowitz.Core.Module;
using Microsoft.Web.Infrastructure.DynamicModuleHelper;
using ZeroProximity.DeviceDetection;
using umbraco;
using umbraco.cms.businesslogic.template;
[assembly: PreApplicationStartMethod(typeof(MobileRewriteModule), "Start")]
@brendankowitz
brendankowitz / gist:4167197
Created November 29, 2012 06:39
Better than revealing module pattern?
(function ($, exports) {
'use strict';
exports.Site = function (el) {
this.el = el;
/* Private Methods */
function initSearch() {
el.find("#site-search-form").submit(function (e) {
var searchInput = $(this).find("input[type='text']");
@brendankowitz
brendankowitz / SetListItemDataTemplateState.cs
Created May 21, 2013 11:23
WinRT + ExtendedVisualStateManager + Caliburn = Visual State Groups in a ListItem DataTemplate
public class SetListItemDataTemplateState
{
public void SelectionChanged(dynamic sender, dynamic args)
{
var container = sender.ItemContainerGenerator;
foreach (var item in args.AddedItems)
{
var listItem = container.ContainerFromItem(item);
var layout = FrameworkElementExtensions.FindDescendantByName(listItem, "RootLayout");
ExtendedVisualStateManager.GoToElementState(layout, "ToSelected", true);
@brendankowitz
brendankowitz / modalBootstrapDialog.js
Last active December 22, 2015 02:29
Durandal modal dialog modification for bootstrap dialogs
define(['./composition', './system', './viewModel'],
function (composition, system, viewModel) {
var contexts = {},
modalCount = 0;
function ensureModalInstance(objOrModuleId) {
return system.defer(function (dfd) {
if (typeof objOrModuleId == "string") {
system.acquire(objOrModuleId).then(function (module) {
@brendankowitz
brendankowitz / azure prob.png
Last active December 27, 2015 02:08
An Azure situation...
azure prob.png
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
@brendankowitz
brendankowitz / BundleConfig.cs
Last active August 29, 2015 14:01
Register directory based script bundles in an mvc project
var applicationPath = app.Server.MapPath("~/");
var contentBundleBasePath = app.Server.MapPath("~/Content/bundles");
bundles.CreateRecursiveBundles(
contentBundleBasePath,
applicationPath,
contentBundleBasePath);
bundles.CreateRecursiveBundles(app.Server.MapPath("~/Views"), applicationPath, applicationPath);
bundles.CreateRecursiveBundles(app.Server.MapPath("~/Areas"), applicationPath, applicationPath);
@brendankowitz
brendankowitz / JsReferenceBundleOrderer.cs
Created February 4, 2015 03:48
Js Bundle Orderer using comment references. Using QuickGraph nuget package.
public class JsReferenceBundleOrderer : IBundleOrderer
{
readonly Regex _referenceRegex = new Regex(@"///\s*<reference\s+path\s*=\s*""(?<filename>.*?)""\s*(?:/>|>)", RegexOptions.Compiled);
public IEnumerable<BundleFile> OrderFiles(BundleContext context, IEnumerable<BundleFile> files)
{
var bundleFiles = files as List<BundleFile> ?? files.ToList();
var adjacencyGraph = new AdjacencyGraph<string, Edge<string>>();
var topSort = new TopologicalSortAlgorithm<string, Edge<string>>(adjacencyGraph);
@brendankowitz
brendankowitz / Extensions.cs
Created June 11, 2015 19:59
Returns the property name from a lambda expression
using System;
using System.Linq;
using System.Linq.Expressions;
namespace Extensions
{
public class PropertyExtension
{
public static string GetFor<T>(Expression<Func<T>> propertyNameLambda)
{
<!DOCTYPE html>
<html class="en-us" lang="en">
<head>
<title></title>
</head>
<body>
Crash!!
<h3><a id="download" name="download">Improved download experience</a></h3>