Skip to content

Instantly share code, notes, and snippets.

View juanpicado's full-sized avatar
🎯
Focusing

Juan Picado juanpicado

🎯
Focusing
View GitHub Profile
@juanpicado
juanpicado / escodegen.js
Last active March 20, 2016 17:05
escodegen.js
var escodegen = require('escodegen');
var js = escodegen.generate({
"type": "VariableDeclaration",
"start": 0,
"end": 6,
"range": [
0,
6
],
"declarations": [
@juanpicado
juanpicado / estraverse.js
Last active March 20, 2016 16:58
Estraverse example
var estraverse = require('estraverse');
var escodegen = require('escodegen');
var ast = require('./ast');
var a = ast.esprimaAST();
// 'function bar(){ var longVariable; console.log("foo", longVariable);}'
estraverse.traverse(a, {
enter: function (node, parent) {
if (node.type == 'Identifier' && node.name == 'longVariable') {
console.log(node);
node.name = 'b';
@juanpicado
juanpicado / scope.js
Created March 20, 2016 17:24
Esprima and Escope
var escope = require('escope');
var esprima = require('esprima');
var estraverse = require('estraverse');
var code = require('./ast');
var ast = code.esprimaAST();
var scopeManager = escope.analyze(ast);
var scopes = scopeManager.scopes;
// return an array of scopes, in our example we have 2, the global and inside of the function
var currentScope = scopeManager.acquire(ast);
// return the global scope, the current one
@juanpicado
juanpicado / esrefactor.js
Last active March 20, 2016 18:51
esrefactor example
var esrefactor = require('esrefactor');
var code = require('./ast');
// function bar(){ var a; console.log("foo", a);}
var ctx = new esrefactor.Context(code.codeVariable);
var id = ctx.identify(21);
console.log("id", id);
//id { identifier: { type: 'Identifier', name: 'a', range: [ 20, 21 ] },
// declaration: { type: 'Identifier', name: 'a', range: [ 20, 21 ] },
@juanpicado
juanpicado / esmangle
Last active March 20, 2016 18:56
esmangle example
var esprima = require('esprima');
var esmangle = require('esmangle');
var escodegen = require('escodegen');
var codeBase = require('./code');
var ast = esprima.parse(codeBase.wholeFile());
var result = esmangle.mangle(ast); // gets mangled result
console.log(escodegen.generate(result, {
format: {
renumber: true,
@juanpicado
juanpicado / ast-types.js
Created March 20, 2016 19:33
ast-types.js
var assert = require("assert");
var n = require("ast-types").namedTypes;
var b = require("ast-types").builders;
var fooId = b.identifier("foo");
var ifFoo = b.ifStatement(fooId, b.blockStatement([
b.expressionStatement(b.callExpression(fooId, []))
]));
assert.ok(n.IfStatement.check(ifFoo));
@juanpicado
juanpicado / idea.vmoptions
Created June 25, 2016 08:58 — forked from ilguzin/idea.vmoptions
High performance Mac OS X IntelliJ IDEA options: /Applications/IntelliJ IDEA 12 CE.app/bin/idea.vmoptions
-server
-Xms512m
-Xmx2048m
-XX:MaxPermSize=512m
-XX:ReservedCodeCacheSize=256m
-XX:+UseCodeCacheFlushing
-XX:+UseCompressedOops
-XX:+UseConcMarkSweepGC
-XX:+AggressiveOpts
-XX:+CMSClassUnloadingEnabled
@juanpicado
juanpicado / gist:6d7f18e2916a9e65259da9d35e39c8f0
Created September 3, 2016 19:58 — forked from jimbojsb/gist:1630790
Code highlighting for Keynote presentations

Step 0:

Get Homebrew installed on your mac if you don't already have it

Step 1:

Install highlight. "brew install highlight". (This brings down Lua and Boost as well)

Step 2:

function Foo(x, y) {
this.x = x;
this.y = y;
}
var A = new Foo(1,3);
var B = new Foo(2,4);
// we modify the object
B.z = 4;
@juanpicado
juanpicado / async_function.js
Created September 23, 2016 18:16
async function example
const myPromise = (a) => {
return Promise.resolve(a);
}
async function foo() {
let d1 = await myPromise(1).then(console.log);
let d2 = await myPromise(2).then(console.log);;
}