Skip to content

Instantly share code, notes, and snippets.

View davidchambers's full-sized avatar

David Chambers davidchambers

View GitHub Profile
@jethrolarson
jethrolarson / _usage.js
Last active April 25, 2016 01:10
xface - Functional Interface library for typed common apis
//Some fantasy implementations
const Just = require('./just')
const Cant = require('./cant')
const List = require('./list')
//Spec file that defines what arguments are used for type identification
const fantasy = require('./fantasy')
//The magic.
const {chain, map, index} = require('../../src/xface')(fantasy, [Just, Cant])
@jethrolarson
jethrolarson / exampleUsage.js
Last active June 26, 2016 21:05
AGeneric interface fantasy-land objects
var Maybe = require('./maybe.js')
var List = require('./list.js')
//Pass fantasy implementations to it
var {concat, map} = require('fantasy')({Maybe, List})
mapDouble = map(a => 2 * a)
mapDouble([1, 2])
//[2, 4]
@tel
tel / ProfunctorLens.js
Last active October 23, 2023 20:32
Pure Profunctor Lenses in Javascript (redux)
/* eslint-disable new-cap */
/**
* Lens types.
* ===========
*
* a * b = {fst: a, snd: b}
* a + b = {index: Boolean, value: a | b}
*
* Iso s t a b = forall (~>) . Profunctor (~>) => (a ~> b) -> (s ~> t)
@tel
tel / Profunctor.js
Last active April 3, 2019 01:51
"Pure-profunctor" lenses in Javascript (!)
/// PRELIMINARIES
/**
* Generalized "products" of any size. For gluing things together. A tuple is a
* "2"-meet.
*
* The type `Meet a b c d ...` indicates a `Meet` of the given size with values
* at each type in the sequence.
*/
@jethrolarson
jethrolarson / future_example.js
Last active August 29, 2015 14:23
Playing with Future
var R = require('ramda');
var Future = require('ramda-fantasy').Future;
//Wrap ajax in a future
//:: String -> Future String
var fetch = function(url) {
return new Future(function(rej, res){
var oReq = new XMLHttpRequest();
oReq.addEventListener("load", res, false);
oReq.addEventListener("error", rej, false);
oReq.addEventListener("abort", rej, false);
@raine
raine / ramda
Last active May 4, 2020 12:14
Browse Ramda documentation in Terminal
#!/usr/bin/env bash
# Browse Ramda documentation in Terminal
# Requires jq and a tool such as fzf or peco for interactive filtering
LATEST="http://raine.github.io/ramda-json-docs/latest.json"
DOCS_URL="http://ramdajs.com/docs/"
json=$(curl -s $LATEST)
functions=$(echo "$json" | jq -r '.[] | if .sig and (.sig | length > 0) then .name + " :: " + .sig else .name end')
hush :: Either e a -> Maybe a
hush = either (const Nothing) Just
toId :: JObject -> Maybe Number
toId o = fromNumber <|> fromString
where
fromNumber = hush $ o .? "id"
fromString = do
s <- hush $ o .? "id"
mfilter (isNan >>> not) Just (readFloat s)
; The official HD AI
; An Artificial Intelligence Script written by Archon and Promiskuitiv
; Get in contact with Promiskuitiv by sending a mail to neuernamae@web.de
; List of taunts it reacts to:
; Standard taunts.
; 33 - Stop slinging resources. If slinging is requested early and is immediately canceled it may mess up the strategy.
; 38 - Sling Resources. Human player only, stops any unit production except for civilian units.
@parshap
parshap / install-vbox-guest-additions.sh
Created July 31, 2014 19:35
Install VirtualBox Guest Additions on a headless server
wget http://download.virtualbox.org/virtualbox/4.3.12/VBoxGuestAdditions_4.3.12.iso
sudo mkdir /media/iso
sudo mount -o loop ./VBoxGuestAdditions_4.3.12.iso /media/iso
sudo bash /media/iso/VBoxLinuxAdditions.run --nox11
sudo umount /media/iso
var Option = require('fantasy-options')
var Some = Option.Some;
var None = Option.None;
var Compose = function(x){
this.val = x;
}
Compose.prototype.map = function(f){
return new Compose(this.val.map(function(u){return u.map(f); }));