Skip to content

Instantly share code, notes, and snippets.

View mauriciosoares's full-sized avatar
:shipit:
[object Object]

Mauricio Soares mauriciosoares

:shipit:
[object Object]
  • Automatiq
  • São Paulo
View GitHub Profile
const array = [[1,2,[3]],4];
function flatten(arr) {
return arr.reduce((newArray, item) => {
return [
...newArray,
...(Array.isArray(item) ? flatten(item) : [item])
]
}, []);
}
async function loadNumber() {
return fetch(API_URL);
}
const number = await loadNumber();
// essa linha nao executa enquanto `loadNumber` nao tiver acabado
const multiplyRequest = fetch(API_URL, {data: number});
const sumRequest = fetch(API_URL, {data: number});
const promise = Promise.all(multiplyRequest, sumRequest).then((multiply, sum) => {
/* @flow */
import getDocument from 'shared/utils/get-document';
export default function submitGoogleForm(fields, mapper, googleFormId='google-form') {
const document = getDocument();
const formData = Object.keys(mapper).reduce((data, key) => {
data[mapper[key]] = fields[key];
return data;
}, {});
@mauriciosoares
mauriciosoares / doubleclick.js
Created October 19, 2015 20:07
rxjs double click example
let clickStream = Rx.Observable.fromEvent(document.getElementById('link'), 'click');
clickStream
.buffer(clickStream.debounce(250))
.map(list => list.length)
.filter(x => x === 2)
.subscribe(() => {
console.log('doubleclick');
})
@mauriciosoares
mauriciosoares / composition.js
Created September 21, 2015 21:22
Composition example
let barker = (state) => ({
bark: () => console.log(`woof ${state.name}`)
});
let machine = (name) => {
let state = {
name
}
return Object.assign({},
javascript:require(["ns/log"],function(log){log.verbose = true;log.verboseLevel = 0;log.dump();});
var subscriptions = {};
var Mediator = function() {};
Mediator.prototype.subscribe = function(key, callback, context) {
subscriptions[key] = subscriptions[key] || [];
subscriptions[key].push({
callback: callback,
context: context || window
function User(attrs) {
for(var name in attrs) {
this[name] = attrs[name];
}
}
User.build = function(attrs) {
if(arguments.length === 2) {
attrs = {
name: arguments[0],
[1,2].forEach(function() {
console.log(this); // window
});
[1,2].forEach(function() {
console.log(this); // {}
}.bind({}));
function Sale(price) {
this.price = price || 100;
}
Sale.prototype.getPrice = function() {
return this.price;
};
Sale.prototype.decorate = function(decorator) {
var overrides = this.constructor.decorators[decorator],