Skip to content

Instantly share code, notes, and snippets.

View harboe's full-sized avatar

Dennis Harboe Christensen harboe

View GitHub Profile
(function (ko, handlers, unwrap, extend) {
"use strict";
extend(handlers, {
href: {
update: function (element, valueAccessor) {
handlers.attr.update(element, function () {
return { href: valueAccessor() };
});
}
},
@harboe
harboe / DateTimeExtensions.cs
Created August 12, 2013 09:42
DateTime Extensions: Display a pretty print of the duration since the original DateTime and Now. For instance: Yesterday, 1min ago. 2weeks, etc.
using System;
public static class DateTimeExtensions
{
public static string ToPrettyPast(this DateTime d)
{
var timeSpan = DateTime.Now.Subtract(d);
if (timeSpan.Days == 1)
return "Yesterday.";
@harboe
harboe / linq.js
Created June 26, 2013 23:39 — forked from rniemeyer/linq.js
/*--------------------------------------------------------------------------
* linq.js - LINQ for JavaScript
* ver 2.2.0.2 (Jan. 21th, 2011)
*
* created and maintained by neuecc <ils@neue.cc>
* licensed under Microsoft Public License(Ms-PL)
* http://neue.cc/
* http://linqjs.codeplex.com/
*--------------------------------------------------------------------------*/
@harboe
harboe / ko.observableArray.fn.toColumn.js
Last active December 19, 2015 00:49
Knockout ObservableArray extension that will transform an array into a multidimension array (or columns) while still maintaining sort direction from left to right so that: [1, 2, 3, 4, 5, 6, 7] becomes [ [1, 4, 7], [2, 5], [3, 6] ] with 3 columns. fiddler demo: http://jsfiddle.net/harboe/RGBdq/16/
// Knockout ObservableArray extension that will transform an array
// into a multidimension array (or columns) while still maintaining
// sort direction from left to right so that: [1, 2, 3, 4, 5, 6, 7]
// becomes [ [1, 4, 7], [2, 5], [3, 6] ] with 3 columns.
//
// fiddler demo:
// http://jsfiddle.net/harboe/RGBdq/16/
ko.observableArray.fn.toColumn = function(data, numberOfColumns) {
var generateColumns = function(data, numberOfColumns) {
@harboe
harboe / WebApiConfig.cs
Created June 22, 2013 15:02
WebApi QueryString Mapping Settings Expample
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
using System.Web.Http.Tracing;
using System.Net.Http.Formatting;
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
@harboe
harboe / XElementExtension.cs
Created June 16, 2013 08:50
XElement Extensions: InnerXml, GetAttributeValue
using System;
using System.Text;
using System.Xml.Linq;
public static class XElementExtension
{
public static string InnerXml(this XContainer element)
{
var innerXml = new StringBuilder();
@harboe
harboe / EventArgs.cs
Last active December 18, 2015 13:39
Simple Generic EventArgs<T> implementation,
using System;
using System.Security.Permissions;
using System.Runtime.Serialization;
/// <summary>
/// Generic implementation of the <c>System.EventArgs</c> the base class for
/// classes containing event data.
/// </summary>
[Serializable]
public class EventArgs<TData> : EventArgs, ISerializable
@harboe
harboe / ko.bindingsHandlers.search.js
Last active December 18, 2015 09:49
Knockout custom binding handle for simplifying the search input text. usage: data-bind="search: viewModelCallbackFunction" 1. It will clear all the content when the user hits esc. 2. There is a timer that will auto sumbit. 3. Manually submit thought the Enter key
(function(undefined) {
// custom binding handle for simplifying the search
// input text.
//
// usage: data-bind="search: viewModelCallbackFunction"
//
// 1. It will clear all the content when the user hits esc.
// 2. There is a timer that will auto sumbit.
// 3. Manually submit thought the Enter key
@harboe
harboe / ConsoleArgumentParser.cs
Last active December 18, 2015 09:39
A simple console argument parser.
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
public static class ArgumentParser
{
@harboe
harboe / ValidateModelStateAttribute.cs
Created June 7, 2013 18:20
snippet from somewhere. An ActionFilter for return the corrent Html Repsonse Code for an invalid model state in ASP.NET WebApi
using System;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http.Controllers;
using System.Web.Http.Filters;
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public class ValidateModelStateAttribute : ActionFilterAttribute
{