Skip to content

Instantly share code, notes, and snippets.

@disnet
disnet / gist:4489250
Last active August 13, 2019 15:04
osx - force skim to always autoupdate
defaults write -app Skim SKAutoReloadFileUpdate -boolean true
@disnet
disnet / gist:4973724
Created February 17, 2013 21:57
sed - convert literate haskell to plain haskell
sed '
s/^>//
t
s/^ *$//
t
s/^/-- /
' in.lhs > out.hs
macro class {
case $className { constructor $constParam $constBody $rest ... } => {
function $className $constParam $constBody
class $className { $rest ... }
}
case $className { private_function $pMethodName $pMethodParam $pMethodBody $rest ...} => {
function $pMethodName $pMethodParam $pMethodBody
class $className { $rest ... }
@disnet
disnet / gist:6024833
Last active December 19, 2015 22:08
simple object structure case matching macro
macro _match_cond {
case $o ($field) => {
(typeof $o.$field !== 'undefined')
}
case $o ($field $rest ...) => {
_match_cond $o ($field) && _match_cond $o ($rest ...)
}
}
macro _match_var {
@disnet
disnet / gist:6024991
Created July 17, 2013 22:09
cond macro
macro _arms {
case (default => $value:expr) => {
else {
return $value;
}
}
case (case $cond:expr => $value:expr) => {
if($cond) {
return $value;
}
macro forThing {
case $val ($a:expr, $b:expr) => {(function($val){forEach.call($b, this)}).bind($a)}
case $val ($a:expr) => {(function($val){forEach.call(val,this)}).bind($a)}
}
function makeMutationObserver(tag){
var queue= tag.queue,
put= queue.put.bind(queue),
mutationAddObserve= forThing val (put, val.getElementsByTagName(this.tag)),
mutationObserver= forThing val (mutationAddObserve, val.addedNodes),
mutationsObserver= forThing val (mutationObserver)
@disnet
disnet / gist:6171843
Created August 7, 2013 07:06
thinking about sweet.js and code completion

Let's say you want to implement TypeScript with macros:

function foo(str: string) {
    return str.toUpperCase()
    //        ^
    // want to provide completion here
}

So we define the function macro:

@disnet
disnet / gist:6735679
Created September 27, 2013 21:47
hygiene
var random = function(seed) { /* ... */ }
let m = macro {
rule {()} => {
var n = random(42); // ...
}
}
macro = {
rule { > { $body ... } } => { function foo() { $body ...} }
}
=> { return 42; }
@disnet
disnet / let_async.js
Last active December 31, 2015 04:28
sweet.js: async macro
let let = macro {
rule { async $vars ... = $fname ... ($params ...); $rest ...} => {
$fname ... ($params ..., function (err, $vars ...) {
if (err) throw err;
$rest ...
})
}
}
var buffer = new Buffer(1024);