Skip to content

Instantly share code, notes, and snippets.

@disnet
disnet / highlight.sh
Created Oct 21, 2011
running pygments on the command line
View highlight.sh
pygmentize -f rtf -O fontface=Menlo -o examples.rtf examples.coffee
@disnet
disnet / let.coffee
Created Dec 5, 2011
let in coffeescript
View let.coffee
lets = (vals, fn) -> fn.apply @, vals
lets [1, [2, 3]], (a, [b, c]) ->
a is 1
b is 2
c is 3
View test.coffee
class HashMap
# non-implementation of a HashMap :)
get: (key) -> @[key]
put: (key, val) -> @[key] = val
HashMapC = (keyContract, valContract) ->
?{
get: ((keyContract) -> valContract)
put: (keyContract, valContract) -> Any
View gist:3147381
== Access of unallocated memory ==
address 0
at test_unallocated (file_name.js:3:0)
== Access of uninitialized memory ==
address 0
at test_unallocated (file_name.js:3:0)
== Free of unallocated memory ==
address 8184
@disnet
disnet / gist:3407999
Created Aug 20, 2012 — forked from johnkpaul/gist:2361303
gruntjs Mocha task
View gist:3407999
/*
* grunt
* https://github.com/cowboy/grunt
*
* Copyright (c) 2012 "Cowboy" Ben Alman
* Copyright (c) 2012 John K. Paul @johnkpaul
* Licensed under the MIT license.
* http://benalman.com/about/license/
*/
@disnet
disnet / hoisting.md
Created Sep 5, 2012
JavaScript var hoisting
View hoisting.md

Here's the standard example:

var x = "bar";
(function() {
  console.log(x) // undefined
  var x = 42;
})()

But what happens when you have a parameter?

@disnet
disnet / scheme.sjs
Created Oct 8, 2012
start of scheme in sweet.js (modified from http://pastebin.com/0nPBg8LY)
View scheme.sjs
macro sexp {
case () => {
;
}
case ($p) => {
$p
}
case ($x $y) => {
$x($y);
}
View gist:3855533
macro conspair {
case [$head] => { [$head] }
case [$head $tail ...] => {
[$head, conspair [$tail ...]]
}
}
conspair [1 2 3 4]
@disnet
disnet / annotate.js
Created Oct 16, 2012
parameter annotations (type, contract, etc.) in sweet.js
View annotate.js
macro def {
case $name:ident ( $($params:ident : $type:ident) (,) ...) $body => {
// just throwing away the type annotation. The semantics of type
// annotations left as an exercise to the reader :)
function $name ($params (,) ...) $body
}
}
def add (a : Number, b : Number) {
return a + b;
@disnet
disnet / gist:4165526
Created Nov 28, 2012
javascript - sweet.js macro checking for null
View gist:4165526
macro null_helper {
case ($processed ...) ($rest) => {
$processed (.) ... . $rest
}
case ($processed ...) ($rest_head $rest ...) => {
$processed (.) ... . $rest_head
&& null_helper ($processed ... $rest_head) ($rest ...)
}
}
You can’t perform that action at this time.