Skip to content

Instantly share code, notes, and snippets.

View themindfuldev's full-sized avatar

Tiago Romero themindfuldev

View GitHub Profile
@themindfuldev
themindfuldev / graph-coloring.js
Created December 1, 2018 06:30
Graph coloring
/*
https://www.interviewcake.com/question/javascript/graph-coloring
Given an undirected graph with maximum degree D, find a graph coloring using at most D+1 colors.
Our solution runs in O(N+M)O(N+M) time but takes O(D)O(D) space. Can we get down to O(1)O(1) space?
*/
function GraphNode(label) {
this.label = label;
this.neighbors = new Set();
@themindfuldev
themindfuldev / example.js
Created January 18, 2015 02:29
jasmine-precondition
describe('the preCondition instruction', function () {
var counter1 = 0,
counter2 = 0,
interval;
beforeEach(function(done) {
interval = setInterval(function(){
counter1 += 100;
}, 100);
@themindfuldev
themindfuldev / example.js
Last active August 29, 2015 14:13
marionette-vdom demonstration
var MyItemView = VDOMItemView.extend({
template: _.template('<p><a><b>w<%= content %></b></a></p>'),
modelEvents: {
"change": "render"
}
});
@themindfuldev
themindfuldev / index.js
Created December 21, 2014 22:44
requirebin sketch
// example using the raf module from npm. try changing some values!
var requestAnimationFrame = require("raf")
var canvas = document.createElement("canvas")
canvas.width = 500
canvas.height = 500
document.body.appendChild(canvas)
var context = canvas.getContext("2d")
@themindfuldev
themindfuldev / bad_hoisting.js
Last active December 19, 2015 10:59
This gist just shows some good usage and bad usage examples about Hoisting concept in Javascript.
function stepSum() {
var total = 0;
for (var i = 0; i < arguments.length; i++) {
var parameter = arguments[i];
if (typeof(parameter) !== 'number') {
parameter = parseInt(parameter);
}
setTimeout(function() {
if (!isNaN(parameter)) {
total += parameter;