Skip to content

Instantly share code, notes, and snippets.

@bcrisp
bcrisp / graph.json
Last active April 19, 2017 19:19
D3 Canvas Force Network
{"nodes":[{"id":"a","group":1},{"id":"b","group":1},{"id":"c","group":1}],"links":[{"value":1,"source":"a","target":"b"}]}
@bcrisp
bcrisp / .block
Last active April 5, 2017 02:58 — forked from mbostock/.block
Force-Directed Lattice
license: gpl-3.0
height: 960
@bcrisp
bcrisp / .block
Created January 26, 2017 22:50 — forked from mbostock/.block
Mobile Patent Suits
license: gpl-3.0
@bcrisp
bcrisp / README.md
Last active August 31, 2016 23:44
Containers as Monads

Containers as Monads

There's a common analogy of viewing Monads as containers, but what about the dual concept: utilizing containers as monads?

Docker

In Docker we can spin up containers to execute arbitrary commands using docker run. This will take a Docker image and apply the supplied commands to it; in other words, a String -> Container. Let's say I then want to apply the results of that computation and "roll" it to another container, so I need something to take a Container -> Container. With these two conditions I define a ContainerIO type to hold containers.

Caveats

  1. This only works in GHCI currently
@bcrisp
bcrisp / .block
Last active August 25, 2016 23:00 — forked from mbostock/.block
Blocks Graph
license: gpl-3.0
height: 960
@bcrisp
bcrisp / gist:e1f00bfdcd03e09f1ba9
Created April 23, 2015 20:17
Collaborative Ops
Collaborative Operations is the next evolutionary step in DevOps movement. While DevOps takes the stance of infrastructure as code, removing silos between development and operations, and releasing early and often.
Collaborative Ops holds the following views:
- Your infrastructure is code and can be treated as such. Operational stacks can be versioned in Git, rolled back, fast-forwarded, and programmed against. Collaborative Ops allows the entire stack to be represented as a WSDL-like schema that can be programmed against at compile time rather than run time.
- Infrastructure is a Read Eval Print Loop of modules that can be loaded and unloaded in real time.
- Systems are represented categorically, with useful notation borrowed directly from category theory. Isomorphisms serve as interfaces; if my Apache web server has an isomorphism to an nginx config, then I can switch back and forth between them with zero configuration.
@bcrisp
bcrisp / README.md
Last active August 29, 2015 14:16 — forked from mbostock/.block

This D3 example shows how to constrain the position of nodes within the rectangular bounds of the containing SVG element. As a side-effect of updating the node's "cx" and "cy" attributes, we update the node positions to be within the range [radius, width - radius] for x, [radius, height - radius] for y. If you prefer, you could use the each operator to do this as a separate step, rather than as a side-effect of setting attributes.

@bcrisp
bcrisp / gist:7939460
Created December 13, 2013 03:37
Unique Pairs Sketch of correctness: Case for single element: let an array of non-negative integers "val" have one element, such that the sole index is i = j = 0. If val[i] + val[j] = 100 (i.e. val[0] = 50) then output the values, otherwise return void. Proof by contradiction: let some value j < i result in val[j] + val[i] = 100. Now since i rang…
using System;
using System.Collections.Generic;
namespace gauss
{
class MainClass
{
public static void Main (string[] args)
{
int[] nums = new int[]{0, 1, 100, 99, 0, 10, 90, 30, 55, 33, 55, 75, 50, 51, 49, 50, 51, 49, 51};
@bcrisp
bcrisp / README.md
Last active February 1, 2018 13:36
κατά: Catamorphisms in JavaScript

Catamorphisms in JavaScript

Inspired by Brian McNamara's work on catamorphisms in F#, this is a proof-of-concept implementation for a tail-recursive JavaScript function using continuation-passing style.

Due to differences in the way D3.js handles vertices and edges for force-directed graph and tree layouts, this is actually more than strictly catamophorphic: since it can take a tree to any other structure, including another tree, code editor and D3.js visualization tool for translating JavaScript to abstract syntax trees and then to a tree. This only parses a small subset of JavaScript code, but it demonstrates catamorphisms, continuation-passing style, and utilizes tail-recursion (when JavaScript supports it.)

Although this project uses several JavaScript libraries for visualization and parsing, the actual AST destruction is implemented in pure J