Skip to content

Instantly share code, notes, and snippets.

View mrtnbroder's full-sized avatar
🕶️
λ

Martin Broder mrtnbroder

🕶️
λ
View GitHub Profile
// Detect autoplay
// ---------------
// This script detects whether the current browser supports the
// autoplay feature for HTML5 Audio elements, and it sets the
// `AUTOPLAY` variable accordingly.
// Used in the Meteor app [PicDinner](http://picdinner.com)

Contract Killer

The popular open-source contract for web designers and developers by Stuff & Nonsense

  • Originally published: 23/12/2008
  • Revised date: 15/12/2013
  • Original post

@mrtnbroder
mrtnbroder / react-app-file-structure
Last active July 30, 2020 18:54 — forked from ryanflorence/react-app-file-structure
React Directory Structure
.
├── assets
│   ├── images
│   ├── sass/less/stylus/css
├── lib
│   ├── actions
│   ├── components
│   │   ├── __tests__
│   │   │ └── Avatar.test.jsx
│   │   └── Avatar.jsx
@mrtnbroder
mrtnbroder / fetch-helpers.js
Created May 18, 2017 08:48 — forked from maddie927/fetch-helpers.js
Fetch API Helpers
import fetch from 'isomorphic-fetch'
const setupRequestOptions = (options = {}, overrideMethod) => {
if (overrideMethod) options.method = overrideMethod
if (!options.headers) options.headers = {}
options.credentials = 'same-origin'
return options
}
const setupJsonRequestOptions = (options, overrideMethod) => {
@mrtnbroder
mrtnbroder / bifunctor-profunctor.js
Created November 1, 2018 08:59 — forked from richdouglasevans/bifunctor-profunctor.js
The main examples from the "Bifunctor + Profunctor" post.
const { Left, Right } = require("fantasy-eithers");
const daggy = require("daggy");
Function.prototype.map = function(f) {
return x => f(this(x));
};
//- Where everything changes...
const login = user => (user.name == "Tom" ? Right(user) : Left("Boo"));
@mrtnbroder
mrtnbroder / Comonad.js
Created November 1, 2018 09:00 — forked from richdouglasevans/Comonad.js
Code for Game of Life from the Comonad article.
const { tagged } = require("daggy");
const Pair = tagged("Pair", ["_1", "_2"]);
//+ data Store p s = Store (p -> s) p
const Store = tagged("Store", ["lookup", "pointer"]);
Array.prototype.equals = function(that) {
return (
this.length === that.length &&
@mrtnbroder
mrtnbroder / extend.js
Created November 1, 2018 09:00 — forked from richdouglasevans/extend.js
All the example code from the Extend article of Fantas, Eel, and Specification.
const daggy = require("daggy");
const { uncurryN } = require("wi-jit");
Array.prototype.empty = () => [];
const Sum = daggy.tagged("Sum", ["value"]);
Sum.prototype.concat = function(that) {
return Sum(this.value + that.value);
};
@mrtnbroder
mrtnbroder / monad.js
Created November 1, 2018 09:00 — forked from richdouglasevans/monad.js
The Monad example from the Fantasy Land series.
const Promise = require("fantasy-promises");
const daggy = require("daggy");
//- Regular `compose` - old news!
//+ compose :: (b -> c)
//+ -> (a -> b)
//+ -> a -> c
const compose = f => g => x => f(g(x));
//- `chain`-sequencing `compose`, fancily
@mrtnbroder
mrtnbroder / chainRec.js
Created November 1, 2018 09:00 — forked from richdouglasevans/chainRec.js
Code from the fantas-eel post on ChainRec.
const daggy = require("daggy");
const { Loop, Done } = daggy.taggedSum("Loop", {
Loop: ["b"],
Done: ["a"]
});
Array.empty = () => [];
const Pair = T => {
@mrtnbroder
mrtnbroder / semigroup.js
Created November 1, 2018 09:00 — forked from richdouglasevans/semigroup.js
Fantas, Eel, and Specification
import { tagged } from "daggy";
const First = tagged("First", ["val"]);
First.prototype.concat = function(that) {
return this;
};
const Min = tagged("Min", ["val"]);