Skip to content

Instantly share code, notes, and snippets.

@tuchida
tuchida / comment.js
Created February 23, 2014 03:06
heredoc macro
macro <<EOS {
case { $_ } => {
var comments = #{$_}[0].token.leadingComments;
var text = '';
if (comments) {
text = comments.map(function(c) {
return c.type === 'Block' ? c.value.replace(/^(\r\n|\n|\r)/, '').replace(/(\r\n|\n|\r)$/, '') : c.value;
}).join('\r\n');
}
return [makeValue(text, #{here})];
@tuchida
tuchida / E4X.java
Created March 26, 2014 23:31
E4X in Nashorn
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
public class E4X {
public static void main(String[] args) {
System.out.println("E4X: " + System.getProperty("nashorn.lexer.xmlliterals"));
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("js");
try {
@tuchida
tuchida / searchtools.js.diff
Created May 16, 2014 06:53
Sphinxの全文検索を複合語に強くする
diff --git a/_build/html/_static/searchtools.js b/_build/html/_static/searchtools.js
index 3499624..6843d3b 100644
--- a/_build/html/_static/searchtools.js
+++ b/_build/html/_static/searchtools.js
@@ -81,7 +81,22 @@ var Search = {
},
setIndex : function(index) {
+ function objToSortArray(terms) {
+ var res = [];
@tuchida
tuchida / cjs.html
Created July 16, 2014 23:46
jsとcssを1ファイルに
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="test.cjs">
</head>
<body>
<script src="test.cjs"></script>
</body>
</html>
@tuchida
tuchida / delaunay.js
Created February 20, 2015 01:09
delaunay.js ES6Ver
// ref. http://qiita.com/edo_m18/items/7b3c70ed97bac52b2203
(require => {
require("babel/polyfill");
function Point(x, y) {
this.x = x;
this.y = y;
}
Object.assign(Point.prototype, {
macro forOf {
case (var $name:ident of $array) $body => {
(function(array) {
for (var i = 0, len = array.length; i < len; i++) {
var $name = array[i];
$body
}
})($array);
}
}
@tuchida
tuchida / async.js
Created October 30, 2012 15:36
async/await in sweet.js
macro async {
case :{ $rest } => {
$rest
}
case :{ $head $rest ... } => {
$head
async: { $rest ... }
}
case :{ var $x:ident = await($yield:ident, $y ...); $rest ... } => {
(function($yield) {
class MyClass {
constructor(a, b, c) {
this.sum_ = a + b + c;
}
sum() {
return this.sum_;
}
}
console.log(new MyClass(2, 3, 4).sum());
@tuchida
tuchida / brainfuck.js
Created March 11, 2013 14:49
Brainfuck in sweet.js
macro bf {
case ($body ...) => {
eval('var p = 0, b = [], buf = new Buffer(1);');
_bf($body ...);
}
}
macro _bf {
case (>) => {
eval('p++;');
}
@tuchida
tuchida / brainfuck.js
Last active December 14, 2015 19:39 — forked from tuchida/brainfuck.js
macro bf {
case : { $body ... } => {
(function() {
var env = {
p: 0,
b: [],
buf: new Buffer(1)
};
bf_tokenizer[env]($body ...);
})();