Skip to content

Instantly share code, notes, and snippets.

@michaelficarra
michaelficarra / CoffeeScript.Project.mk
Created December 13, 2012 16:48
a standard Makefile skeleton for CoffeeScript projects
default: all
# configure these:
LIBDIR = lib
SRCDIR = src
TESTDIR = test
BROWSERIFIED = ProjectName.js
MAIN = $(LIBDIR)/project-main-entry-point.js
ROOT = $(shell pwd)
@michaelficarra
michaelficarra / task.coffee
Created December 6, 2012 06:03
comonadic futures on top of Q
Q = require './q'
class exports.Task
constructor: (@promise) ->
value: null
reason: null
result: ->
unless @promise.isResolved()
@michaelficarra
michaelficarra / comonadic-futures.coffee
Created December 3, 2012 21:01
comonadic futures library that can't possibly work
flip = (fn) -> (a, b) -> fn b, a
id = (x) -> x
class exports.Future
constructor: (fn) ->
(flip setTimeout) 0, =>
try
@result = fn()
catch e
import Control.Applicative ((<*>))
import Control.Parallel (par)
class Comonad w where
extend :: (w a -> b) -> w a -> w b
duplicate :: w a -> w (w a)
extract :: w a -> a
-- if monads are monoids on functions which produce side effects,
--
@michaelficarra
michaelficarra / gist:3710374
Created September 12, 2012 22:17
first step toward self-hosting
$ make && (for file in src/*.coffee; do echo -n "$file: "; bin/coffee --js <"$file" >/dev/null && echo '*success*'; done)
make: Nothing to be done for `default'.
src/command.coffee: *success*
src/compiler.coffee: *success*
src/functional-helpers.coffee: *success*
src/helpers.coffee: *success*
src/js-nodes.coffee: *success*
src/module.coffee: *success*
src/nodes.coffee: *success*
src/optimiser.coffee: *success*
@michaelficarra
michaelficarra / preprocessor.coffee
Created September 4, 2012 19:44
generated source map example
fs = require 'fs'
{EventEmitter} = require 'events'
StringScanner = require 'cjs-string-scanner'
inspect = (o) -> (require 'util').inspect o, no, 9e9, yes
# TODO: better comments
# TODO: support win32-style line endings
@michaelficarra
michaelficarra / compilations.md
Created August 22, 2012 22:34
"rest" operator compilations

(a..., b, c) -> ...

function(/*a...,*/ b, c) {
  var a, _numArgs;
  _numArgs = arguments.length;
  a = [];
  if(_numArgs > 2) {
    a = __slice.call(arguments, 0, _numArgs - 2);
 b = arguments[_numArgs - 2];
@michaelficarra
michaelficarra / range.js
Created August 20, 2012 17:25
Is there an easier way to do this?
// Assuming ES5 builtins, create an inclusive range of numbers between an arbitrary, integral `a` and `b`
Array(Math.abs(a - b) + 1).join('|').split('|').map(function(){ var i = a; return a < b ? function(){ return i++; } : function(){ return i--; }; }())
@michaelficarra
michaelficarra / gist:3373751
Created August 16, 2012 21:21
CoffeeScriptRedux error output
Error: Syntax error on line 86, column 7: unexpected ','
83 : test 'dedented comma style', ->
84 : eq 3, [
85 : 0
86 : ,
^^ :~~~~~~~^
87 : 0
88 : ,
89 : 0
@michaelficarra
michaelficarra / CoffeeScriptRedux.js
Created August 14, 2012 00:20
compilation output comparison (preprocessor.coffee)
// Generated by CoffeeScript 2.0.0
void function () {
var EventEmitter, fs, inspect, Preprocessor, StringScanner;
fs = require('fs');
EventEmitter = require('events').EventEmitter;
StringScanner = require('cjs-string-scanner');
inspect = function (o) {
return require('util').inspect(o, false, 9e9, true);
};
this.Preprocessor = Preprocessor = function (super$) {