Skip to content

Instantly share code, notes, and snippets.

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

Aaron Powell aaronpowell

😶‍🌫️
View GitHub Profile
@aaronpowell
aaronpowell / StringTypeProvider.fs
Created February 6, 2015 11:02
A basic Type Provider for taking a string and making something silly.
namespace Samples.FSharp.StringTypeProvider
open System
open System.Reflection
open Samples.FSharp.ProvidedTypes
open Microsoft.FSharp.Core.CompilerServices
open Microsoft.FSharp.Quotations
[<TypeProvider>]
type StringTypeProvider(config: TypeProviderConfig) as this =
@aaronpowell
aaronpowell / CommandSender.fs
Created October 15, 2014 10:24
Nimbus + F#
open System
open Config
open MyApp.Messages
[<EntryPoint>]
let main argv =
let bus = busBuilder()
{ Value = "Hey from F#" }
|> bus.Send
@aaronpowell
aaronpowell / CustomerController.fs
Created September 23, 2014 23:10
F# workshop ioc
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 August 14, 2014 23:40
jq - a simple cli for JSON querying
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 July 14, 2014 02:05
Parse an Octopus deployment and determine duration of each step
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 July 8, 2014 22:56
Simple request asserting
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 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 / app.js
Last active August 29, 2015 14:01
Express.js + Sweet.js + modules
var express = require('express');
var app = express();
get '/404' send(404) 'Not Found'
get '/foo' with (req, res) {
res.json({ foo: 'bar' });
}
@aaronpowell
aaronpowell / express.sjs
Last active August 29, 2015 14:01
Express DLS
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 06:23
Type annotations and checking with Sweet.js
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);