Skip to content

Instantly share code, notes, and snippets.

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")]
@ashmind
ashmind / MonoidsInCSharp.cs
Created March 11, 2011 23:15
Monoids in C# as I see them
public class Monoid<T> {
public T None { get; private set; }
public Func<T, T, T> Operation { get; private set; }
public Monoid(Func<T,T,T> operation, T none) {
this.Operation = operation;
this.None = none;
}
}
AutoMap.AssemblyOf<...>(new BusinessModelAutomapping())
.Conventions.AddAssembly(Assembly.GetExecutingAssembly())
.UseOverridesFromAssembly(Assembly.GetExecutingAssembly())
.Alterations(a => a.AddFromAssembly(Assembly.GetExecutingAssembly()));
@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) {
private class QueryPropagatingRoute : RouteBase {
private readonly RouteBase target;
private readonly string[] queryStringKeys;
public QueryPropagatingRoute(RouteBase target, params string[] queryStringKeys) {
this.target = target;
this.queryStringKeys = queryStringKeys;
}
public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values) {
@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 / 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 / htmlpeek.js
Last active December 10, 2015 16:38
Just a small fun thing — if used as a bookmarklet (crunched with http://ted.mielczarek.org/code/mozilla/bookmarklet.html), creates a circular hole in the current page that you can use to peek at html code beneath. Chrome/Safari only.
var init = function($) {
$("<style type='text/css'></style>").text('.cx { background: #f5f2f0; color: black; }' +
' .cx .tag { color: #999; }' +
' .cx .tag .title, .cx .css .attribute { color: #905; }' +
' .cx .tag .attribute, .cx .string, .cx .css .tag, .cx .css .class { color: #690; }' +
' .cx .tag .value, .cx .keyword { color: #07a; }' +
' .cx { font-family: Consolas, Courier New; position: absolute; z-index: 50000; left: 0; top: 0; right: 0; white-space: pre; }')
.appendTo($('head'));
var source = $('<code></code>').text(document.documentElement.outerHTML)
// https://gist.github.com/ashmind/8749472
// jQuery plugin to load JS files from GitHub.
// NOT FOR PRODUCTION, use something like Bower instead.
// This is for quick iteration sites like CodePen or JSFiddle.
(function($) {
// this API requires blob SHA. get the SHA by requesting
// https://api.github.com/repos/:owner/:repo/contents/:path
$.loadScriptsFromGitHub = function(scripts, success) {
function drawLizard(context, size) {
var c = context;
var s = size;
c.save();
c.strokeStyle = '#000000';
c.fillStyle = '#000000';
var m = c.moveTo.bind(c);
var l = c.lineTo.bind(c);
c.beginPath();