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
$.ajax({ | |
type: ‘GET’, | |
url: ‘/my/url’, | |
success: function(resp) {}, | |
error: function() {} | |
}); |
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 _ = require(‘lodash’) | |
var object = { ‘a’: [{ ‘b’: { ‘c’: 3 } }] }; | |
_.get(object, ‘a[0].b.c’); | |
// => 3 | |
_.get(object, [‘a’, ‘0’, ‘b’, ‘c’]); | |
// => 3 | |
_.get(object, ‘a.b.c’, ‘default’); |
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 object = { a: [{ b: { c: 3} }] } | |
var res = null | |
try { | |
res = object.a.b.c | |
} catch (err) { | |
res = ‘default’ | |
} |
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 object = { a: [{ b: { c: 3} }] } | |
var res = null | |
if (!object.a.length > 0 || !object.a[0].b || !object.a[0].b.c) { | |
res = ‘default’ | |
} | |
res = object.a.shift().b.c |
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
if (self.fetch) { // Verificamos se existe suporte do navegador ao Fetch | |
var myImage = document.querySelector('img'); | |
fetch('arquivo.jpg') // Busca um arquivo de uma URL | |
.then(function(response) { // Trata a resposta em uma promise | |
return response.blob(); // Busca o blob desta resposta | |
}) | |
.then(function(myBlob) { // Passa o blob para outra função | |
var objectURL = URL.createObjectURL(myBlob); // Cria uma URL | |
myImage.src = objectURL; // Adiciona ao SRC da imagem |
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 mongoose = require('mongoose') | |
const express = require('express') | |
const bodyParser = require('body-parser') | |
const expressJWT = require('express-jwt') | |
const jwt = require('jsonwebtoken') | |
const apiRoutes = require('./routers/api') | |
const app = express() | |
app.use(bodyParser.urlencoded()) | |
app.use(expressJWT({ secret: 'string de secret' })) // Utilizamos nosso middleware JWT |
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 mongoose = require('mongoose') | |
const express = require('express') | |
const bodyParser = require('body-parser') | |
const expressJWT = require('express-jwt') | |
const jwt = require('jsonwebtoken') | |
const apiRoutes = require('./routers/api') | |
const app = express() | |
app.use(bodyParser.urlencoded()) | |
app.use(expressJWT({ secret: 'string de secret' }).unless({ path: ['/login']})) |
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 mongoose = require('mongoose') | |
const express = require('express') | |
const bodyParser = require('body-parser') | |
const expressJWT = require('express-jwt') | |
const jwt = require('jsonwebtoken') | |
const apiRoutes = require('./routers/api') | |
const app = express() | |
app.use(bodyParser.urlencoded()) | |
app.use( |
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
module.exports = 1 | |
module.exports = NaN | |
module.exports = 'foo' | |
module.exports = { foo: 'bar' } | |
module.exports = [ 'foo', 'bar' ] | |
module.exports = function foo () {} | |
module.exports = () => {} |
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
export default = 1 | |
export default = NaN | |
export default = 'foo' | |
export default = { foo: 'bar' } | |
export default = [ 'foo', 'bar' ] | |
export default = function foo () {} | |
export default = () => {} |