Skip to content

Instantly share code, notes, and snippets.

View aaronpowell's full-sized avatar
😶‍🌫️

Aaron Powell aaronpowell

😶‍🌫️
View GitHub Profile
@aaronpowell
aaronpowell / numbersWithoutTrailingZero.js
Created December 13, 2013 02:49
AngularJS number directive that'll show whole numbers or round to the required number of decimal places
app.filter('numbersWithoutTrailingZero', function ($filter) {
return function (input, decimalPlaces) {
if (input % 1) {
return $filter('number')(input, decimalPlaces);
}
return $filter('number')(input, 0);
};
});
@aaronpowell
aaronpowell / gist:7763203
Created December 3, 2013 02:55
Dynamically creating expression trees
void Main()
{
var pi = typeof(Foo).GetProperty("Bar");
Expression<Func<Foo, string>> x = f => f.Bar;
x.Dump();
var p = Expression.Parameter(pi.DeclaringType, "f");
@aaronpowell
aaronpowell / find-prev.js
Created November 13, 2013 02:42
Single-level tree walker for js-git
//assumes that the hash you want and the repo are obtainable via closure scope
function findPrevious(commit, previousCommit) {
repo.load(commit.parents[0], function (err, obj) {
if (obj.type !== 'commit') {
console.error(obj);
throw 'Unexpected type returned';
}
repo.load(obj.body.tree, function (err, tree) {
if (tree.type !== 'tree') {
@aaronpowell
aaronpowell / gist:7231110
Created October 30, 2013 11:27
DDD Brisbane

Title

JavaScript, aww yeah!

Abstract

Anything that can be written in JavaScript will be written in JavaScript.

So let's take that and go with two really out there ideas and get them working in JavaScript, first let's look at LINQ and by extensions PLINQ, and how you can create proper lazy collections in JavaScript.

@aaronpowell
aaronpowell / gist:6695293
Created September 25, 2013 04:55
Copy Umbraco files on build
<Target Name="BeforeBuild">
<ItemGroup>
<UmbracoFiles Include="..\packages\UmbracoCms.6.1.5\UmbracoFiles\umbraco\**\*;" />
<UmbracoClientFiles Include="..\packages\UmbracoCms.6.1.5\UmbracoFiles\umbraco_client\**\*;" />
</ItemGroup>
<Copy SourceFiles="@(UmbracoFiles)" DestinationFiles="@(UmbracoFiles->'umbraco\%(RecursiveDir)%(Filename)%(Extension)')" />
<Copy SourceFiles="@(UmbracoClientFiles)" DestinationFiles="@(UmbracoClientFiles->'umbraco_client\%(RecursiveDir)%(Filename)%(Extension)')" />
</Target>
@aaronpowell
aaronpowell / .gitignore
Created May 31, 2013 05:02
ScriptCS libgit2 sample. You need to manually copy the NativeBinaries folder from the LibGit2Sharp folder into the bin folder if you're using 0.5.* of ScriptCS
bin
packages
@aaronpowell
aaronpowell / PreExecutingResult.cs
Created April 18, 2013 04:45
Execute a Razor view server side in a MVC project. I'm returning the HTML in a JSON blob for this example
public class PreExecutingResult : JsonResult {
private ViewResult viewResult;
private object model;
public PreExecutingResult(string viewName, object model) {
viewResult = new ViewResult {
ViewName = viewName
};
viewResult.ViewData.Model = model;
glimpse.render.engine = (function($, pubsub) {
var providers = {},
addition = function (scope, data, metadata, insertType, filterType) {
var html = $('<div>' + build(data, metadata) + '</div>').find('.glimpse-row-holder:first > .glimpse-row'),
rowHolder = scope.find('.glimpse-row-holder:first'),
scopeTarget = rowHolder.find('> .glimpse-row:' + filterType);
if (scopeTarget.length == 0) {
scopeTarget = rowHolder;
insertType = 'appendTo';
@aaronpowell
aaronpowell / dal.cs
Created January 22, 2013 00:10
Umbraco unit test mocking
public class DataLayer {
private readonly INeedAnAbstraction abs;
public DataLayer() : this(new UmbracoAbstraction()) {}
public DataLayer(INeedAnAbstraction abs) {
this.abs = abs;
}
public IEnumerable<Node> FilterSomeNodes(string docTypeAlias) {
@aaronpowell
aaronpowell / gist:4255474
Created December 11, 2012 02:41
Valid typescript
var foo = 'baz';
var bar: any;
bar = foo === 'true' ? true : foo === 'false' ? <any>false : foo;