This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Validation = require('folktale/validation'); | |
const { Success, Failure } = Validation; | |
// valida se uma string não é vazia | |
const hasText = (value, name) => | |
if (value != "") Success(value) | |
else Failure([{ code: 'required', name }]); | |
// valida se uma selecao não é vazia | |
const hasSelection = (value, name) => |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require("fs"); | |
var helpers = require("./helpers"); | |
var path = require("path"); | |
function readFile(path, options) { | |
return new Promise(function(resolve, reject) { | |
fs.readFile(path, options, function(err, data) { | |
if (err) reject(err); | |
else resolve(data); | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
var promise = { | |
state: 'pending', | |
value: null, | |
dependencies: [], | |
then: function(expression) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var async = require('async'); | |
async.eachSeries(array, function(item, callback){ | |
callAsyncFunction(item, function(error, data) { | |
if (error) { | |
return callback(error); | |
} else { | |
async.eachSeries(arrayTwo, function(sItem, sCallback) { | |
count++; | |
callAnotherAsyncFunction(item + sItem, function(error, data) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Logic MUST BE identical to the synchronous way: | |
// https://gist.github.com/melissamarima/2b9e8594892103dbc02c | |
var mongoose = require('mongoose'); | |
var collectionASchema = new mongoose.Schema({field1: Number, field2: Number}); | |
var collectionBSchema = new mongoose.Schema({field1: Number, field2: Number}); | |
collectionASchema.index({field1: 1}); | |
collectionBSchema.index({field1: -1}); | |
mongoose.model('collectionA', collectionASchema); | |
mongoose.model('collectionB', collectionBSchema); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* Assume bhttp-get is available here somehow *) | |
let HTTP = { | |
def get: url | |
(* This would actually need to be imported properly. Yeah, FFI sucks, but oh well... *) | |
Task from-promise: (FFI invoke: bhttp-get in-context: unit with-arguments: [FFI export: url]) | |
} | |
do { | |
response <- HTTP get: "http://somesite.com/all-the-urls.txt"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.commands = { | |
mb: 'musicbox', | |
musicbox: function (target, room, user) { | |
if (!this.canBroadcast()) return; | |
var parts = target.split(','); | |
if (!target) return this.sendReply("/musicbox link, link, link - parses it to be in a music box"); | |
var parsedParts = parts.map(parse); | |
Promise.all(parsedParts).then(function(parts) { | |
var str = parts.join(''); | |
this.sendReply('str is ' + str); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function pipeline(fs, val, done) { | |
if (fs.length === 0) done(null, val) | |
else fs[0](val, function(err, val) { | |
if (err) done(err) | |
else pipeline(fs.slice(1), val, done) | |
}) | |
} | |
pipeline([ | |
asyncFunctionOne, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var models = [{ | |
name: 'Jonathan', | |
location: 'Earth' | |
}, { | |
name: 'Joe', | |
location: 'Mars' | |
}] | |
var ps = models.map(function(model) { |
NewerOlder