- mongo and mongoose pro: there is no schema, no need to migrate
- knex pro: simple
- sequelize: pro: can automatic sync (useful in development)
This file contains 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
// import posts from https://gist.github.com/Chun-Yang/c19fd8c3209212fd820831a9e816a9d7 | |
posts = [] | |
// authors | |
authorsMap = {} | |
posts.forEach(post => { | |
authorsMap[post.author] = authorsMap[post.author] || {author: post.author, reactionsCount: 0, commentsCount: 0}; | |
authorsMap[post.author].reactionsCount += post.reactionsCount; | |
authorsMap[post.author].commentsCount += post.commentsCount; | |
}) |
This file contains 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
[ | |
{ | |
"title": "I am a mediocre developer", | |
"author": "Nikita Sobolev", | |
"date": "Mar 13 '18", | |
"tags": [ | |
"#meta", | |
"#career", | |
"#beginners", | |
"#productivity" |
This file contains 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
// navigate to https://dev.to/top/infinity and scroll untill postsData's length is more than 500 | |
postsCount = 500 | |
postsData = [...document.querySelectorAll('#substories .single-article')] | |
.slice(0, postsCount) | |
.map(post => { | |
try { | |
const [author, date] = post.querySelector('h4').textContent.trim().split('・') | |
const postData = { | |
title: post.querySelector('h3').textContent.trim(), |
This file contains 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
import React from 'react'; | |
import { createStore, combineReducers, applyMiddleware, compose } from 'redux'; | |
import { ApolloClient, ApolloProvider, createNetworkInterface } from 'react-apollo'; | |
import accessToken from './reducers/accessToken' | |
const SERVER_URL = process.env.REACT_APP_SERVER_URL | |
const networkInterface = createNetworkInterface({ | |
uri: `${SERVER_URL}/graphql`, | |
}) |
This file contains 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
import { Strategy, ExtractJwt } from 'passport-jwt'; | |
import passport from 'passport'; | |
import { MongoClient } from 'mongodb'; | |
function authenticateHOF({ mongoUrl, collectionName = 'users' }) { | |
const mongoPromise = MongoClient.connect(mongoUrl); | |
passport.use(new Strategy( | |
{ | |
jwtFromRequest: ExtractJwt.fromHeader('authorization'), |
This file contains 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
import { makeExecutableSchema } from 'graphql-tools'; | |
const typeDefs = ` | |
type Query { | |
} | |
type Mutation { | |
} | |
`; |
This file contains 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
{ | |
"name": "server", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"scripts": { | |
"start": "nodemon index.js --exec babel-node --presets es2015,stage-2" | |
}, | |
"test": "echo \"Error: no test specified\" && exit 1" |
This file contains 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 getFirstNumber(text) { | |
const matches = text.match(/\d+/) | |
return matches ? parseInt(matches[0]) : 0 | |
} | |
$$('.issue-card').map(c => getFirstNumber(c.innerText)).reduce((a, b) => a + b, 0) |
This file contains 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
start = moment('7/31/2017') | |
end = moment('10/31/2017') | |
function format(m) { | |
return m.format('MM/DD/YYYY') | |
} | |
for (var i = 0; i < end.diff(start, 'day'); i += 7) { | |
startOfWeek = moment(start).add(i, 'day').isoWeekday(1) | |
endOfWeek = moment(start).add(i, 'day').isoWeekday(5) |
NewerOlder