Skip to content

Instantly share code, notes, and snippets.

@ashmind
ashmind / FSharpCheat1.fs
Created August 2, 2012 02:07
F# first class generic function cheating
open System
type Test() =
let f = fun x -> x
member this.F with get() = f
let t = Test()
ignore (t.F "5") // 1
// ignore (t.F 5) // 2
Console.WriteLine(t.F.GetType().BaseType)
@ashmind
ashmind / linq.fsx
Created July 17, 2012 11:45
AlmostLinq
open System
let items = [-2; -1; 0; 1; 2]
let where = Seq.filter
let select = Seq.map
let each = Seq.iter
let positive x = x > 0
@ashmind
ashmind / dcraw.gamma_curve.c
Created June 26, 2011 06:14
gamma_curve method from dcraw
void CLASS gamma_curve (double pwr, double ts, int mode, int imax)
{
int i;
double g[6], bnd[2]={0,0}, r;
g[0] = pwr;
g[1] = ts;
g[2] = g[3] = g[4] = 0;
bnd[g[1] >= 1] = 1;
if (g[1] && (g[1]-1)*(g[0]-1) <= 0) {
AutoMap.AssemblyOf<...>(new BusinessModelAutomapping())
.Conventions.AddAssembly(Assembly.GetExecutingAssembly())
.UseOverridesFromAssembly(Assembly.GetExecutingAssembly())
.Alterations(a => a.AddFromAssembly(Assembly.GetExecutingAssembly()));
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Compilation;
using System.Web.Mvc;
using System.Web.Razor;
using System.Web.WebPages.Razor;
[assembly: PreApplicationStartMethod(typeof(AshMind.Web.Mvc.Razor.RazorJavaScriptSupport), "SetupAll")]
using System;
namespace SomeUnit {
public class AssertHelper {
public static AssertHelper Assert { get; } = new AssertHelper();
}
}
namespace SomeUnit.Extensions {
public static class AssertExtensions {
@ashmind
ashmind / ContractResolverWithPatchSupport.cs
Last active August 29, 2015 14:14
WebApi Patch<T> Design (at the moment needs AshMind.Extensions and InfoOf from NuGet)
using System;
using System.Collections.Generic;
using System.Linq;
using AshMind.Extensions;
using Newtonsoft.Json.Serialization;
namespace PatchDesignDemo {
public class ContractResolverWithPatchSupport : DefaultContractResolver {
private readonly IContractResolver _inner;
public class Node {}
public class NodeA : Node {}
public class NodeB : Node {}
public class NodeBProcessor : Processor<NodeB> {
}
public class ProcessingDispatcher {
public void Dispatch(Node node) {
var processor = FindBestProcessorFor(node);
// current
pvc.Task("build", () => {
pvc.Source("WebApplication.sln")
.Pipe(new PvcMSBuild(
buildTarget: "Clean;Build",
enableParallelism: true
))
.Pipe(new PvcSomethingElse(...));
});
angular.module('...').directive('ancestorClass', function() {
'use strict';
function link(scope, element, attrs) {
var targets = element.parents().filter(attrs.selector);
scope.$watch(attrs.class, function(value) {
for (var key in value) {
targets.toggleClass(key, value[key]);
}
}, true);