Skip to content

Instantly share code, notes, and snippets.

View b2rsp's full-sized avatar

Vitor Gonçalves b2rsp

View GitHub Profile
@b2rsp
b2rsp / flattenArray.js
Last active January 3, 2018 17:09
Flatten an nested arrays of integers into a flat array of integers written in ES6.
/**
* Flatten an nested arrays of integers into a flat array of integers.
* @param {Array} rawArray - Array of numbers
* @param {Array} rawArray - Flatten array for recursion
* @return {Array} - Flatten array of numbers
*
* Tests can be found https://gist.github.com/b2rsp/c584a48f2e6593d4bd58ac00b9d948be
*/
function flatten (rawArray, flattenArray = []) {
if (! (rawArray instanceof Array)) throw Error('Param passed is not an array');
@b2rsp
b2rsp / testsFlattenArray.js
Created January 3, 2018 15:58
Tests for a function that flatten an nested arrays of integers into a flat array of integers. (ES6 required)
describe("Flatten an nested arrays of integers into a flat array of integers.", function() {
it("Return an empty array when empty array provided", function() {
expect(flatten([])).toEqual([]);
});
it("Return a flat array when a flat array is provided", function() {
expect(flatten([4, 5])).toEqual([4, 5]);
});
@b2rsp
b2rsp / moment.workdays.js
Created September 8, 2017 12:02 — forked from ioleo/moment.workdays.js
introduce 'workdays' mode to moment.js add/subtract methods (PL national holidays)
(function (undefined) {
/**
* moment.easter
* Source: https://github.com/zaygraveyard/moment-easter
* License: MIT
*/
moment.easter = function Easter20ops(year) {
var a = (year / 100 | 0) * 1483 - (year / 400 | 0) * 2225 + 2613;
var b = ((year % 19 * 3510 + (a / 25 | 0) * 319) / 330 | 0) % 29;
var c = 148 - b - ((year * 5 / 4 | 0) + a - b) % 7;
@b2rsp
b2rsp / better-nodejs-require-paths.md
Created November 2, 2016 17:39 — forked from branneman/better-nodejs-require-paths.md
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

var Article = require('../../../models/article');

Those suck for maintenance and they're ugly.

Possible solutions

@b2rsp
b2rsp / introrx.md
Created April 27, 2016 17:08 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing
<snippet>
<content><![CDATA[
<!doctype html>
<!-- paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/ -->
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
<head>
<meta charset="utf-8">
(function () {
var myPrototype = {
methodA: function methodA() {},
methodB: function methodB() {},
methodC: function methodC() {}
};
window.createFoo = function createFoo() {
return (Object.create(myPrototype));
};