Skip to content

Instantly share code, notes, and snippets.

/*
Copyright (c) 2010 Microsoft Corporation. All rights reserved.
Use of this sample source code is subject to the terms of the Microsoft license
agreement under which you licensed this sample source code and is provided AS-IS.
If you did not accept the terms of the license agreement, you are not authorized
to use this sample source code. For the terms of the license, please see the
license agreement between you and Microsoft.
*/
@alfeg
alfeg / gist:4059091
Created November 12, 2012 12:29
RequiredIf
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;
namespace KI.Web.Admin.Common.Validation
{
public class RequiredIfGreaterValidator : DataAnnotationsModelValidator<RequiredIfGreaterAttribute>
{
public RequiredIfGreaterValidator(ModelMetadata metadata, ControllerContext context, RequiredIfGreaterAttribute greaterAttribute)
@alfeg
alfeg / Main.cs
Created October 18, 2012 13:50
GUIDs generation performance test JFF
private static void Main(string[] args)
{
Console.WriteLine("Will generate 70M of Guids.\n\r Flushing timestamps for each 100k guids in one thread");
long i = 0;
long max = 120 * 1000000;
long quant = max / 100l;
var list = new Guid[max];
@alfeg
alfeg / gist:3818602
Created October 2, 2012 12:21
SortBy
public static IQueryable<T> SortBy<T>(this IQueryable<T> source, string propertyName)
{
propertyName = propertyName.Trim();
if (source == null)
{
throw new ArgumentNullException("source");
}
// DataSource control passes the sort parameter with a direction
// if the direction is descending
int descIndex = propertyName.IndexOf(" DESC");
@alfeg
alfeg / RestClientExtensions.cs
Created August 3, 2012 20:54
Restsharp client extensions
using System;
using System.Diagnostics;
using Fasterflect;
using RestSharp;
namespace xxx.xxx.Rest.Client
{
public static partial class RestClientExtensions
{
public static ClientResponse ExecuteItDynamic(this IRestClient client, IRestRequest request)
/// <summary>
/// Controls access to the cached values.
/// </summary>
private static ReaderWriterLockSlim mutex = new ReaderWriterLockSlim(LockRecursionPolicy.NoRecursion);
/// <summary>
/// Gets a values from the cache, adding it if required.
/// </summary>
/// <typeparam name="T">The type of the value.</typeparam>
/// <param name="cacheParameters">The name of the value used to identify it in the cache.</param>
protected static bool IsListSuitableForSimpleAdmin(IList<Record> records)
{
bool returnValue = false;
if (records != null)
{
int sundayCount = 0;
int mondayCount = 0;
int tuesdayCount = 0;
int wednesdayCount = 0;
int thursdayCount = 0;
@alfeg
alfeg / gist:1899750
Created February 24, 2012 09:36
MVC4 SPA Todo Sample
/// <reference path="_references.js" />
(function (window, undefined) {
// Define the "MyApp" namespace
var MyApp = window.MyApp = window.MyApp || {};
// TodoItem class
var entityType = "TodoItem:#TodoApp.Models";
MyApp.TodoItem = function(data) {
var self = this;
@alfeg
alfeg / gist:1514174
Created December 23, 2011 13:12
Perlin Fire
// Variable usage: (* marks globals, all other variables are used for various purposes by various parts of the code)
// a = calculator
// b* = random data
// c* = main canvas
// d* = main canvas style / main canvas context
// e = calculator
// f =
// g* = main canvas composite operations
// h* = 300 (height)
// i = counter
@alfeg
alfeg / GenericHelpers.cs
Created October 13, 2011 11:02
Html helper for script jquery templates
public static class GenericHelpers
{
public static HtmlTemplate HtmlTemplate(this HtmlHelper html, object htmlAttributes)
{
return new HtmlTemplate(html, htmlAttributes);
}
}