Skip to content

Instantly share code, notes, and snippets.

@kevinblake
kevinblake / google-analytics-data-events.js
Last active May 29, 2021 08:24
Fire Google Analytics Events using data attributes for label, action and category fields
var googleDataEvents = {
pageTracker: null,
init: function (document) {
document.find("a[data-ga-label],area[data-ga-label]").click(this.trackLink);
},
trackLink: function (e) {
if (_gaq) {
e.preventDefault();
var l = $(this);
var label = l.attr("data-ga-label");
@kevinblake
kevinblake / run.bat
Created December 10, 2012 09:53
Run .NET solution without Visual Studio
SET PORT=8086
SET SOLUTIONNAME=VS.Solution.Filename.sln
SET WEBDIRECTORY=VS.Solution.Web.WorkingDirectory
%WINDIR%\Microsoft.NET\Framework\v4.0.30319\msbuild %CD%\%SOLUTIONNAME%
start "IIS Express %PORT% (%SOLUTIONNAME%)" "%PROGRAMFILES%\IIS Express\iisexpress" /path:%CD%\%WEBDIRECTORY% /port:%PORT%
start "" "http://localhost:%PORT%/"
@kevinblake
kevinblake / ICacheService.cs
Created December 7, 2012 10:03
In Memory Cache wrapper class
using System;
using System.Web.Caching;
namespace Puzzlebox.Caching
{
interface ICacheService
{
T Get<T>(string cacheId, Func<T> getItemCallback) where T : class;
T Get<T>(string cacheId, CacheDependency cacheDependency, DateTime absoluteExpiration, TimeSpan slidingExpiration, Func<T> getItemCallback) where T : class;
}
@kevinblake
kevinblake / ICacheService.cs
Created February 1, 2014 17:06
SimpleCache
internal interface ICacheService
{
T Get<T>(string cacheId, Func<T> getItemCallback) where T : class;
T Get<T>(string cacheId, CacheDependency cacheDependency, DateTime absoluteExpiration, TimeSpan slidingExpiration,
Func<T> getItemCallback) where T : class;
}
@kevinblake
kevinblake / gist:4000628
Created November 2, 2012 11:50
Rebuild Examine Indexes on Application Start
using System.Collections.Generic;
using Examine;
using umbraco.businesslogic;
namespace MyApplication
{
public class ExamineIndexRebuild : ApplicationStartupHandler
{
@kevinblake
kevinblake / DeviceTypeRedirect.cs
Created December 13, 2012 14:45
MVC4 action filter attribute to redirect to a different controller if a page is not valid for mobile/non-mobile context
using System.Web.Mvc;
using System.Web.Routing;
using System.Web.WebPages;
namespace MyNamespace
{
public enum DeviceType {Mobile, Desktop}
public class DeviceTypeRedirect : ActionFilterAttribute
{
@kevinblake
kevinblake / LinkRenderer.cs
Created November 12, 2012 14:26
Umbraco - render local links from string
public class LinkRenderer
{
public static string Transform(string richText)
{
// take a rich text string, parse the local links
Regex ll = new Regex("(/{localLink:)(.*?)}");
var linkRenderer = new LinkRenderer();
MatchEvaluator myEvaluator = new MatchEvaluator(MatchLocalLinks);
; (function ($, window, document, undefined) {
// Create the defaults once
var __indexOf =
[].indexOf || function(item) {
for (var i = 0, l = this.length; i < l; i++) {
if (i in this && this[i] === item) return i;
}
return -1;
};
@kevinblake
kevinblake / ip.py
Last active December 31, 2015 15:18
Sends a pushover message, whenever your public IP address changes.
import requests,json,time,httplib, urllib, socket, yaml
f = open('ip.yaml')
settings = yaml.safe_load(f)
f.close()
while True:
f = open('ipaddress', 'r')
current = f.readline()
r=requests.get(r'http://jsonip.com')
@kevinblake
kevinblake / BlockLabelExtensions.cs
Created November 26, 2013 14:12
Html Helper class to add ASP.NET MVC error messages to a label wrapper class
using System.Linq;
using System.Linq.Expressions;
namespace System.Web.Mvc.Html
{
public static class BlockLabelExtensions
{
public static IDisposable BeginBlockLabel<TModel, TValue>(this HtmlHelper<TModel> html, Expression<Func<TModel, TValue>> expression)
{
string expressionText = ExpressionHelper.GetExpressionText(expression);