Skip to content

Instantly share code, notes, and snippets.

Avatar

yang2007chun Chun-Yang

View GitHub Profile
View dev-to-top-posts-analysis-script.js
// 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
[
{
"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 Jan 7, 2019
dev.to top posts scraping script
View dev-to-top-posts-scraping-script.js
// 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
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
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
import { makeExecutableSchema } from 'graphql-tools';
const typeDefs = `
type Query {
}
type Mutation {
}
`;
View database-and-crm-comparison.md
  • mongo and mongoose pro: there is no schema, no need to migrate
  • knex pro: simple
  • sequelize: pro: can automatic sync (useful in development)
View node-server-es6-package.json
{
"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
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
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)
You can’t perform that action at this time.