Skip to content

Instantly share code, notes, and snippets.

View jquery.loadScriptsFromGitHub.js
// 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) {
View escher.lizard.js
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();
View WorstThings
1. Syntax of `switch`.
2. Syntax of `for`.
3. Array initializers thorugh `{}` (so now it is both `new[] {}` and `{}`)
4. Having both `delegate(..) {..}` and `(..) => ..`.
5. Reserving `*` for rarely-used pointer syntax.
View ancestorClass.js
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);
View PvcBuildIdeas.csx
// current
pvc.Task("build", () => {
pvc.Source("WebApplication.sln")
.Pipe(new PvcMSBuild(
buildTarget: "Clean;Build",
enableParallelism: true
))
.Pipe(new PvcSomethingElse(...));
});
View ExpressionProblem
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);
@ashmind
ashmind / ContractResolverWithPatchSupport.cs
Last active Aug 29, 2015
WebApi Patch<T> Design (at the moment needs AshMind.Extensions and InfoOf from NuGet)
View ContractResolverWithPatchSupport.cs
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;
View AssertExtensibility.cs
using System;
namespace SomeUnit {
public class AssertHelper {
public static AssertHelper Assert { get; } = new AssertHelper();
}
}
namespace SomeUnit.Extensions {
public static class AssertExtensions {
View RazorJavaScriptSupport.cs
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")]
View FluentNHibernate.DesignByCommitee.cs
AutoMap.AssemblyOf<...>(new BusinessModelAutomapping())
.Conventions.AddAssembly(Assembly.GetExecutingAssembly())
.UseOverridesFromAssembly(Assembly.GetExecutingAssembly())
.Alterations(a => a.AddFromAssembly(Assembly.GetExecutingAssembly()));