Skip to content

Commit

Permalink
archive old files
Browse files Browse the repository at this point in the history
  • Loading branch information
hax committed Nov 14, 2012
1 parent cbb9367 commit 597f4dd
Show file tree
Hide file tree
Showing 28 changed files with 1,370 additions and 0 deletions.
58 changes: 58 additions & 0 deletions archive/app.js
@@ -0,0 +1,58 @@
//require('underscore')

/*require('my').load('lib/Tabish/type', function(type){
console.log(type.Class)
})*/


/*
require('my').load('lib/Tabish/iterator', function(m){
console.log(m.Iterator)
console.log(m.StopIteration)
var it = m.Iterator({a:1, b:2})
try {
while (true) {
console.log(it.next())
}
} catch(e) {}
})
require('my').load('lib/Tabish/matcher', function(m){
console.log(m.RegExpMatcherIterator)
var it = m.RegExpMatcherIterator(/l/g, 'Hello world!')
try {
while (true) {
console.log(it.next())
}
} catch(e) {}
})
*/


/*require('my').load('lib/Tabish/tabish', function(m){
console.log(m.parse('Hello!\n Hello 2!'))
})*/

require('my').global.console = console

require('my').load('jedi', function(jedi){

var source = 'html'
var runtime = new jedi.JSRuntime()
var template = runtime.eval(jedi.compileToJS(source))
template.echo = function(s){
console.log(s)
}
template()
})

112 changes: 112 additions & 0 deletions archive/baixing.js
@@ -0,0 +1,112 @@
var express = require('express')

var app = express(), fs = require('fs')

// Configuration
app.configure(function(){
app.set('views', __dirname + '/views');
app.set('view engine', 'jedi');
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(__dirname + '/public'));
});

app.configure('development', function(){
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});

app.configure('production', function(){
app.use(express.errorHandler());
});

require('my').load('jedi', function(jedi){
app.engine('jedi', function __express(path, options, callback) {
//console.log(arguments)
console.log(Object.keys(options))
fs.readFile(path, 'utf-8', function(err, data) {
if (err) callback(err)
else {
try {
var runtime = jedi.JSRuntime()
var source = data
var jsSrc = jedi.compileToJS(source)
var template = runtime.eval(jsSrc)
var result = ''
template.echo = function(s){
result += s
}
template(options.model)
callback(null, result)
} catch(e) {
e.message += jsSrc.replace(/&/g, '&amp;').replace(/</g, '&lt;')
callback(e, jsSrc)
}
}
})
})
})

// Routes

var http = require('http')


app.get('/u/:uid/', function(req, res){
var graphRes = http.get('http://graph.baixing.com' + req.url.slice(2) + 'ad', function(graphRes){
graphRes.setEncoding('utf-8')
var result = ''
graphRes.on('data', function(data){
result += data
})
graphRes.on('end', function(data){
var m = JSON.parse(result)
console.log(m)
ok(res, 'ad', m)
})
})
var graphReq = http.get('http://graph.baixing.com' + req.url.slice(2, -1), function(graphRes){
graphRes.setEncoding('utf-8')
var result = ''
graphRes.on('data', function(data){
result += data
})
graphRes.on('end', function(data){
var m = JSON.parse(result)
console.log(m)
ok(res, 'user', m)
res.render('test', {
model: m
})
})
})
graphReq.on('error', function(e){
console.error(e)
})
})

app.get('/*', function(req, res){
console.log('http://graph.baixing.com' + req.url)
var graphReq = http.get('http://graph.baixing.com' + req.url, function(graphRes){
graphRes.setEncoding('utf-8')
var result = ''
graphRes.on('data', function(data){
result += data
})
graphRes.on('end', function(data){
var m = JSON.parse(result)
console.log(m)
res.render('test', {
model: m
})
})
})
graphReq.on('error', function(e){
console.error(e)
})
});

app.listen(3000, function(){});



File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
63 changes: 63 additions & 0 deletions archive/ometa/api.js
@@ -0,0 +1,63 @@
var ometajs = require('ometajs'),
//uglify = require('uglify-js'),
utils = ometajs.utils,
vm = require('vm'),
//Module = require('module'),
fail = ometajs.globals.fail;
objectThatDelegatesTo = ometajs.globals.objectThatDelegatesTo;

function compilationError(m, i) {
throw objectThatDelegatesTo(fail, {errorPos: i});
};

function translationError(m, i) {
throw fail;
};

function wrapModule(code, options) {
var buf = [
'var ometajs_ = require(\'',
options.root || ometajs.root || 'ometajs',
'\').globals;'
];

Object.keys(ometajs.globals).forEach(function(key) {
buf.push('var ', key, ' = ometajs_.', key, ';\n');
});
buf.push(code);

return buf.join('');
};

function translateCode(code, options) {
options || (options = {});
var tree = ometajs.BSOMetaJSParser.matchAll(code, "topLevel", undefined,
compilationError);

code = ometajs.BSOMetaJSTranslator.match(tree, "trans", undefined,
translationError);

//code = uglify.uglify.gen_code(uglify.parser.parse(code), { beautify: true });

if (options.noContext) return code;

return wrapModule(code, options);
};
exports.translateCode = translateCode;

function evalCode(code, filename, options) {
options || (options = {});
options.noContext = true;

code = translateCode(code, options);
return vm.runInNewContext('var exports = {};' + code + '\n;exports',
utils.clone(ometajs.globals),
filename || 'ometa');
};
exports.evalCode = evalCode;

require.extensions['.ometajs'] = function(module, filename) {
var code = translateCode(require('fs').readFileSync(filename).toString());

module._compile(code, filename);
};
1 change: 1 addition & 0 deletions archive/ometa/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 597f4dd

Please sign in to comment.