- mongo and mongoose pro: there is no schema, no need to migrate
- knex pro: simple
- sequelize: pro: can automatic sync (useful in development)
View dev-to-top-posts-analysis-script.js
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; | |
}) |
View dev-to-top-posts-data.json
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" |
View dev-to-top-posts-scraping-script.js
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(), |
View react-storeHOF.js
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`, | |
}) |
View passport-jwt-mongo-auth.js
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'), |
View graphql-schema.js
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 { | |
} | |
`; |
View database-and-crm-comparison.md
View node-server-es6-package.json
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" |
View sum all times in github project.js
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) |
View create a range of days
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