Skip to content

Instantly share code, notes, and snippets.

View hbarcelos's full-sized avatar
🕶️
I know how to exit Vim :v

Henrique Barcelos hbarcelos

🕶️
I know how to exit Vim :v
View GitHub Profile
@hbarcelos
hbarcelos / promises.cpp
Last active January 7, 2016 00:03
C++ Promises
#include <iostream>
#include <cstdlib>
#include <functional>
template <typename ValueT, typename ReasonT>
class Promise {
private:
enum State {
FULFILLED, REJECTED, PENDING
};
@hbarcelos
hbarcelos / promise.js
Last active January 12, 2016 14:37
Promise A+ Implementation
const State = {
PENDING: Symbol.for('pending'),
FULFILLED: Symbol.for('fulfilled'),
REJECTED: Symbol.for('rejected')
};
function changeState(state) {
if (this.state === state) {
throw new Error('Cannot transition to the same state');
}
describe('Suite', function() {
describe('Inner Suite', function () {
it('should do something when some condition is met', function () {
});
});
});
var chai = require('chai'),
expect = chai.expect,
should = chai.should();
var RoundQueue = require('<round-queue-implementation>'); // We'll fix this later
describe('Round-Queue', function(){
});
var chai = require('chai'),
expect = chai.expect,
should = chai.should();
var RoundQueue = require('<round-queue-implementation>'); // We'll fix this later
describe('Round-Queue', function(){
describe('When adding elements', function(){
it('Should add an element to the end of a non-full queue', function() {
// Queue with max size of 3
var chai = require('chai'),
expect = chai.expect,
should = chai.should();
var RoundQueue = require('<round-queue-implementation>');
describe('Round-Queue', function(){
describe('When adding elements', function(){
'use strict';
var RoundLinkedQueue = function RoundLinkedQueue(size) {
}
module.exports = RoundLinkedQueue;
RoundLinkedQueue.prototype.push = function(data) {
};
'use strict';
var RoundLinkedQueue = function RoundLinkedQueue(maxSize) {
this.maxSize = maxSize;
this.size = 0;
this._root = null;
this._last = null;
}
module.exports = RoundLinkedQueue;
'use strict';
var RoundLinkedQueue = function RoundLinkedQueue(maxSize) {
this.maxSize = maxSize;
this.size = 0;
this._root = null;
this._last = null;
}
module.exports = RoundLinkedQueue;
@hbarcelos
hbarcelos / binary-tree.js
Created September 24, 2016 16:26
Tree iterators using ES6 generators
class BinaryTree {
constructor(value, left=null, right=null) {
this.value = value
this.left = left
this.right = right
}
}