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 / 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);
@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 / who-imported.html
Created October 12, 2015 13:58 — forked from matthewp/who-imported.html
Who imported me?
<script src="node_modules/steal/steal.js"></script>
<script>
var oldNormalize = System.normalize;
System.normalize = function(name, parentName){
return oldNormalize.apply(this, arguments).then(function(name){
if(name === "my/module") {
console.log(name, "is imported by", parentName);
}
return name;
});
-- Exercise 1
-- We need to first find the digits of a number.
-- Define the functions
-- toDigits :: Integer -> [Integer]
-- toDigitsRev :: Integer -> [Integer]
-- toDigits should convert positive Integers to a list of digits. (For 0 or
-- negative inputs, toDigits should return the empty list.) toDigitsRev
-- should do the same, but with the digits reversed.
// write a function that takes an argument
// and returns that argument.
function identity(x) {
return x;
}
// write two binary functions, add and mul,
// that take two numbers and return their sum and product.
require 'date'
def is_valid_date? year, month, day
return false if year < 2000 || year > 2999
Date::valid_date?(year, month, day)
end
class Date
def is_valid_date_for_millenium? millenium
A zero-indexed array A consisting of N integers is given.
An equilibrium index of this array is any integer P such that 0 ≤ P < N
and the sum of elements of lower indices is equal to the sum of elements of higher indices,
i.e. A[0] + A[1] + ... + A[P−1] = A[P+1] + ... + A[N−2] + A[N−1].
Sum of zero elements is assumed to be equal to 0. This can happen if P = 0 or if P = N−1.
For example, consider the following array A consisting of N = 7 elements:
A[0] = -7 A[1] = 1 A[2] = 5
var sum = function sum(x, y) {
if (!x) {
x = 200;
}
if (!y) {
y = 300;
}
return x + y;
@m-mujica
m-mujica / pull_heroku.md
Created June 3, 2013 02:57
Pull heroku database down to local
$ curl -o latest.dump `heroku pgbackups:url -a APPLICATION_NAME`
$ rake db:reset
$ pg_restore --verbose --clean --no-acl --no-owner -h localhost -U root -d YOUR_LOCAL_DB_NAME latest.dump
$ rm latest.dump
@m-mujica
m-mujica / postgresql_setup.md
Last active December 31, 2019 14:43
Set up PostgreSQL for Rails Local Development in Linux