Skip to content

Instantly share code, notes, and snippets.

View SimonRichardson's full-sized avatar
👻
We're going on an adventure!

Simon Richardson SimonRichardson

👻
We're going on an adventure!
View GitHub Profile
@SimonRichardson
SimonRichardson / commonjseverywhere.js
Last active December 27, 2015 08:59
This is the basic template for commonjseverywhere.
(function (global) {
function require(file, parentModule) {
if ({}.hasOwnProperty.call(require.cache, file))
return require.cache[file];
var resolved = require.resolve(file);
if (!resolved)
throw new Error('Failed to resolve module ' + file);
var module$ = {
id: file,
require: require,
@SimonRichardson
SimonRichardson / illegal-invocation.js
Created November 11, 2013 15:38
Why does javascript throw this error - REALLY! Why do we have to have work arounds for native partial applications in javascript. It's bad from a developer point of view that we have to increase boiler plate for functions that should be callable but isn't! Could this be solved by the fat arrow, where the scope is defined already in the function …
function apply(f) {
return function(x) {
return f(x);
};
}
apply(console.log)(2);
// Using fat arrow.
function apply(f) {
@SimonRichardson
SimonRichardson / do-notation.sjs
Last active December 30, 2015 04:19
Sweet.js do notation - (semi-colons are now required)
macro $chain {
case {_ (<-, $x , $do { $block ... } ; $rest ...)} => {
return #{
var $x = function() {
return $do { $block ... }
}();
return function() {
return $do { $rest ... }
}
};
@SimonRichardson
SimonRichardson / gist:7789972
Created December 4, 2013 15:54
Chain effects. Is there a way to represent the .chain.chain.chain scenario some like the do notation? Does the do notation already work with this?
var M = State.StateT(IO),
program = M.lift(init)
.chain(doSomething)
.chain(doSomethingElse)
.chain(doSomethingWicked);
console.log(program.exec([]).unsafePerform());
/*
@SimonRichardson
SimonRichardson / to-learn.md
Last active January 2, 2016 09:39
Things I want to learn
  • Free monads
  • Dependecy injection via Reader monad
  • Monad Transformers - ContT
  • Monad Transformers - ConsoleT
  • Extensible Effects
@SimonRichardson
SimonRichardson / gist:8582718
Created January 23, 2014 17:15
Find quickly the amount of code written in git repo
wc -l $(git ls-files | grep '.*\.js')
@SimonRichardson
SimonRichardson / actors.go
Created February 13, 2014 22:27
PingPong actors in go
package main
import "fmt"
type Envelope struct {
message string
sender Actor
}
type Actor interface {
@SimonRichardson
SimonRichardson / product.go
Last active August 29, 2015 14:01
product
// You can edit this code!
// Click here and start typing.
package main
import "fmt"
type AnyVal interface{}
type IProduct interface {
ProductArity() int
#expr {
width: 100%;
height: 300px;
}
body, textarea, button {
font-size: 12pt;
font-family: monospace;
}
.hover {
require ('./globals')(global); // Mixed in Ramda to global here
var Task = require ('data.future'),
M = require ('control.monads'),
State = require ('fantasy-states'),
Reader = require ('fantasy-readers'),
Tuple2 = require ('fantasy-tuples').Tuple2,
Maybe = require ('data.maybe'),
ST = State.StateT (Task),
App = Reader.ReaderT (ST);