Skip to content

Instantly share code, notes, and snippets.

View Chun-Yang's full-sized avatar

yang2007chun Chun-Yang

View GitHub Profile
@Chun-Yang
Chun-Yang / dev-to-top-posts-analysis-script.js
Created January 7, 2019 06:59
dev.to top posts analysis script
// 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;
})
@Chun-Yang
Chun-Yang / dev-to-top-posts-data.json
Created January 7, 2019 05:48
dev.to top posts data
[
{
"title": "I am a mediocre developer",
"author": "Nikita Sobolev",
"date": "Mar 13 '18",
"tags": [
"#meta",
"#career",
"#beginners",
"#productivity"
@Chun-Yang
Chun-Yang / dev-to-top-posts-scraping-script.js
Created January 7, 2019 05:47
dev.to top posts scraping script
// 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(),
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`,
})
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'),
import { makeExecutableSchema } from 'graphql-tools';
const typeDefs = `
type Query {
}
type Mutation {
}
`;
  • mongo and mongoose pro: there is no schema, no need to migrate
  • knex pro: simple
  • sequelize: pro: can automatic sync (useful in development)
{
"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"
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)
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)