Skip to content

Instantly share code, notes, and snippets.

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

Aaron Powell aaronpowell

😶‍🌫️
View GitHub Profile
@aaronpowell
aaronpowell / DemoTest.cs
Created April 10, 2018 23:43
Testing Fluidity with Chauffeur.TestingTools
using Chauffeur.TestingTools;
using Fluidity.Configuration;
using Fluidity.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Umbraco.Core;
using Xunit;
@aaronpowell
aaronpowell / async.js
Created April 19, 2017 03:58
Abusing JavaScript async
function async(async) {
return new Promise(res =>
setTimeout(() => (console.log(async), res()), 1000)
);
}
async function await() { await async('hello'); }
await();
@aaronpowell
aaronpowell / output.js
Created July 3, 2014 00:00
Implementing the F# pipe forward (|>) operator using Sweet.js
var add = function (x, y) {
return x + y;
};
var log = console.log;
var add1 = add.length <= 1 ? add(1) : add.bind(null, 1);
var three = add1.length <= 1 ? add1(2) : add1.bind(null, 2);
var four = add.length <= [2].length + 1 ? add(2, 2) : add.bind(null, 2, 2);
log(three);
log(four);
@aaronpowell
aaronpowell / foo.fsx
Last active June 21, 2016 01:04
Generic record type
let foo = (bar: 'a) ->
{ something: bar }
let baz = foo(1)
let baz2 = foo("a")
printf "bar: %d" baz.bar
printf "bar2: %s" baz2.bar
@aaronpowell
aaronpowell / StronglyTypeAnonymous.cs
Created December 3, 2010 02:52
Makes an anonymous type implement an interface
//uses ClaySharp: http://clay.codeplex.com
//add the following usings
//using ClaySharp;
//using ClaySharp.Behaviors;
void Main()
{
var foo = TypeMe<IFoo>(new { Id = 1, Name = "Aaron" });
Console.WriteLine(foo.Id);
Console.WriteLine(foo.Name);
@aaronpowell
aaronpowell / runner.js
Created January 11, 2014 07:58
A script for running generator functions
let runner = function (fn) {
if (typeof fn !== 'function') {
throw 'A generator function is expected';
}
var done = false;
var gen = fn();
var val;
while (!done) {
let obj = gen.next(val);
@aaronpowell
aaronpowell / List-RemoteGitBranches.ps1
Last active December 31, 2015 21:39
List remote git branches with a filter
function List-RemoteGitBranches {
param (
[Parameter(Mandatory=$true)]
[string]
$Filter
)
$branches = git branch -r | ?{ $_ -Match $filter }
$count = $branches.Length
@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') {