Skip to content

Instantly share code, notes, and snippets.

View m-mujica's full-sized avatar

Manuel Mujica m-mujica

View GitHub Profile
@m-mujica
m-mujica / johnson.js
Last active June 22, 2021 17:45
Johnson's elementary cycles algorithm and tarjan's strongly connected components
function Graph() {
this.nodes = [];
this.arrows = new Map();
}
// Tarjan's strongly connected components algorithm
Graph.prototype.stronglyConnectedComponents = function tarjan() {
var index = 0;
var stack = [];
var result = [];
@m-mujica
m-mujica / migrate.js
Created September 17, 2018 13:17
Replaces foo.attr() calls with define-map alternatives (when a key has dots like `foo.bar.` or an identifier is passed to .attr, the call is replaced with key.get or key.set, this is from can-key, you need to add the imports)
const fs = require('fs');
const recast = require('recast');
const types = require('ast-types');
const n = types.namedTypes;
const b = types.builders;
const filePath = process.argv[2];
const source = fs.readFileSync(filePath);
const ast = recast.parse(source);