Skip to content

Instantly share code, notes, and snippets.

Manuel Mujica m-mujica

Block or report user

Report or block m-mujica

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@m-mujica
m-mujica / migrate.js
Created Sep 17, 2018
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)
View migrate.js
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 Nov 8, 2017
Johnson's elementary cycles algorithm and tarjan's strongly connected components
View johnson.js
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 = [];
View who-imported.html
<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;
});
View HW01.hs
-- 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.
View functions.js
// 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.
View best_before.rb
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
View equilibrium_index
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
View falsy_values.js
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 Jun 3, 2013
Pull heroku database down to local
View pull_heroku.md
$ 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 Dec 18, 2015
Set up PostgreSQL for Rails Local Development in Linux
View postgresql_setup.md
You can’t perform that action at this time.