Skip to content

Instantly share code, notes, and snippets.

View doug2k1's full-sized avatar

Douglas Matoso doug2k1

  • Campinas - SP - Brazil
View GitHub Profile
// Usando 'class' o 'new' chama o construtor e faz a mesma coisa com o 'this'
class Player {
constructor (name) {
// const this = {}
this.name = name
this.hp = 1000
this.mp = 0
// return this
}
}
@doug2k1
doug2k1 / arrow.js
Created September 6, 2017 13:56
'this' no JavaScript: arrow function - https://blog.dmatoso.com/javascript-this-71dd763aad52
const player = {
name: 'Cloud',
weapon: 'Fusion Sword',
sayNameAndAttack () {
console.log(this.name)
// Uma 'arrow function'!
// O 'this' dentro dela vai ser o mesmo que aqui fora
window.setTimeout(() => {
console.log(`${this.name} ataca com a ${this.weapon}`)
const fse = require('fs-extra')
const path = require('path')
const { promisify } = require('util')
const ejsRenderFile = promisify(require('ejs').renderFile)
const globP = promisify(require('glob'))
const config = require('../site.config')
const srcPath = './src'
const distPath = './public'
@doug2k1
doug2k1 / index.js
Last active October 2, 2017 12:19
Arduino light sensor example
const five = require('johnny-five')
const board = new five.Board()
board.on('ready', () => {
console.log('ready!')
const led = new five.Led(11)
const photoResistor = new five.Sensor({
pin: 'A2',
freq: 100
@doug2k1
doug2k1 / webpack.config.js
Created October 2, 2017 18:04
Webpack multiple CSS entrypoints
const ExtractTextPlugin = require("extract-text-webpack-plugin")
const path = require('path')
module.exports = {
entry: {
main: './src/index.js',
base: './src/css/base.css',
admin: './src/css/admin.css'
},
@doug2k1
doug2k1 / index.js
Created March 11, 2018 21:28
Test model associations
const { Broker, Investment, Transaction, BalanceUpdate } = require('./models');
const test = async () => {
// create broker
const broker = await Broker.create({ name: 'Fooinvest' });
// create investment
const investment = await Investment.create({
name: 'Tesouro Foo',
BrokerId: broker.get('id')
});
const expect = require('chai').expect;
const { Investment, Transaction } = require('../../src/models');
describe('Transaction', () => {
describe('attributes', () => {
it('should have amount and date', async () => {
const transaction = await Transaction.create({
amount: 1,
date: '2018-03-15'
});
scalar Date
type Query {
brokers(limit: Int): [Broker]
broker(id: ID!): Broker
investments(limit: Int): [Investment]
investment(id: ID!): Investment
}
type Broker {
const { GraphQLString } = require('graphql');
const { Broker, Investment, BalanceUpdate, Transaction } = require('../models');
module.exports = {
Query: {
brokers: (obj, args) => Broker.all(args),
broker: (obj, { id }) => Broker.findById(id),
investments: (obj, args) => Investment.all(args),
investment: (obj, { id }) => Investment.findById(id)
},
scalar Date
type Query {
brokers(limit: Int): [Broker]
broker(id: ID!): Broker
investments(limit: Int): [Investment]
investment(id: ID!): Investment
}
type Broker {