Skip to content

Instantly share code, notes, and snippets.

💭
🐱‍🐉

Aaron Powell aaronpowell

💭
🐱‍🐉
Block or report user

Report or block aaronpowell

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View CommandSender.fs
open System
open Config
open MyApp.Messages
[<EntryPoint>]
let main argv =
let bus = busBuilder()
{ Value = "Hey from F#" }
|> bus.Send
View CustomerController.fs
namespace FSharpWeb.Controllers
open System.Web.Mvc
open Services
type CustomersController(service: CustomerService) =
inherit Controller()
member x.Index () =
x.View(service.GetCustomers ())
@aaronpowell
aaronpowell / jq.js
Created Aug 14, 2014
jq - a simple cli for JSON querying
View jq.js
process.stdin.setEncoding('utf8');
var what = process.argv[2] || '';
process.stdin.on('readable', function () {
var chunk = process.stdin.read();
if (chunk) {
var obj = JSON.parse(chunk);
@aaronpowell
aaronpowell / parser.js
Created Jul 14, 2014
Parse an Octopus deployment and determine duration of each step
View parser.js
var dateItems = [].slice.call(document.querySelectorAll('.log-date span'));
var dates = dateItems.map(function (item) {
return { span: item, date: Date.parse(item.getAttribute('title')) };
}).map(function (item, index, arr) {
var next = arr[index + 1] || item;
return {
span: item.span,
date: item.date,
next: next
@aaronpowell
aaronpowell / test.js
Created Jul 8, 2014
Simple request asserting
View test.js
var request = require('requst'); //npm install request
var assert = require('assert'); //build in to Node.js
request('http://httpstat.us/200', function (err, res, body) {
assert.equal(res.statusCode, 200, 'Expected a 200 response');
});
@aaronpowell
aaronpowell / output.js
Created Jul 3, 2014
Implementing the F# pipe forward (|>) operator using Sweet.js
View output.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 / app.js
Last active Aug 29, 2015
Express.js + Sweet.js + modules
View app.js
var express = require('express');
var app = express();
get '/404' send(404) 'Not Found'
get '/foo' with (req, res) {
res.json({ foo: 'bar' });
}
View express.sjs
let get = macro {
rule { $path:lit $do $res:lit } => {
app.get($path, function (req, res) {
res.$do($res);
});
}
rule { $path:lit $do:ident($sc:lit) $res:lit } => {
app.get($path, function (req, res) {
res.$do($res);
res.status($sc);
@aaronpowell
aaronpowell / annotations.sjs
Created May 13, 2014
Type annotations and checking with Sweet.js
View annotations.sjs
macroclass typedef {
pattern { $x:ident : $type:ident }
pattern { $x:ident : $type:lit }
}
let function = macro {
rule { $name ($params:typedef ...) { $body ... } } => {
function $name ($params$x ...) {
$(if (typeof $params$x !== typeof $params$type) {
throw new Error('Found type ' + (typeof $params$x) + ' but expected ' + typeof $params$type);
@aaronpowell
aaronpowell / output.js
Created May 12, 2014
Sweet.js classes combined with type-safe properties via ES6 Proxies
View output.js
function Person(name) {
this.name = name;
return new Proxy(this, {
set: function (target, property, val) {
var currentType = typeof target[property];
var newType = typeof val;
if (property in target && currentType !== newType) {
throw new Error('Property ' + property + ' must be a ' + currentType);
}
target[property] = val;
You can’t perform that action at this time.