Skip to content

Instantly share code, notes, and snippets.

View lubien's full-sized avatar
💭
Teaching people 🔥🦩 LiveView 🔥🦩

Lubien lubien

💭
Teaching people 🔥🦩 LiveView 🔥🦩
View GitHub Profile
Promise.reject('some error')
.catch(err => { throw 'earth is not flat' }) // runs
.catch(err => console.log(err)) // logs 'earth is not flat'
Promise.reject('some error')
.catch(err => { throw err }) // runs
.catch(err => console.log(2)) // runs
Promise.reject('some error')
.catch(err => console.log(1)) // runs
.catch(err => console.log(2)) // never runs
function someHellComputation(initialData) {
return fnA(initialData)
.then(fnB)
.then(fnC)
}
someHellComputation(10)
.then(console.log)
.catch(err => {
// where does err come from: fnA, fnB, fnC?
function someHellComputation(initialData) {
return fnA(initialData)
.then(fnB)
.then(fnC)
}
someHellComputation(10)
.then(console.log)
.catch(console.error)
@lubien
lubien / cb-hell.js
Last active January 23, 2018 00:22
function someHellComputation(initialData, callback) {
fnA(initialData, (err, intermediateData) => {
if (err) return callback(err)
fnB(intermediateData, (err, anotherData) => {
if (err) return callback(err)
fnC(anotherData), (err, finalData) => {
if (err) return callback(err)
callback(null, finalData)
const arr = [
{
id: 10,
title: "Test 10",
item: "Item 1"
},
{
id: 10,
title: "Test 10",
item: "Item 2"
import lazyLoadingRoutes from '../../support/lazyLoadingRoutes'
export default lazyLoadingRoutes([
{ path: '/login', component: 'Login', meta: { requiresAuth: false } },
{ path: '/forgotPassword', component: 'ForgotPassword', meta: { requiresAuth: false } },
{ path: '/forgotEmail', component: 'ForgotEmail', meta: { requiresAuth: false } },
{ path: '/createAccount', component: 'CreateAccount', meta: { requiresAuth: false } }
])
@lubien
lubien / service.js
Last active December 3, 2017 16:59 — forked from viniazvd/service.js
module.exports = {
async signup(name, email, password) {
const exists = await models.user.findOne({ where: { email } })
if (exists) {
throw new Error({ error: 'E-mail já existe. Tente se registrar com outro.' })
}
const passwordEncrypted = await hashing(password)
@lubien
lubien / ramdascript.js
Last active September 15, 2017 00:15
Playing with Ramdascript https://repl.it/LHTR/7
const R = require('ramda')
const
divisibleBy = (n, x) => x % n === 0
, odd = R.compose(R.not, R.partial(divisibleBy, [2]))
, fizzbuzz = x =>
R.ifElse(
R.pipe(R.length, R.equals(0))