Skip to content

Instantly share code, notes, and snippets.

View asamountain's full-sized avatar
🌴
Growing

San asamountain

🌴
Growing
View GitHub Profile
@asamountain
asamountain / stardict-easy-installation.sh
Last active December 22, 2021 23:59
stardict easy installation shell script
#!/bin/bash
# tarball links of dicts
tcide=https://web.archive.org/web/20140917131745/http://abloz.com/huzheng/stardict-dic/dict.org/stardict-dictd_www.dict.org_gcide-2.4.2.tar.bz2
jargon=https://web.archive.org/web/20140917131745/http://abloz.com/huzheng/stardict-dic/dict.org/stardict-dictd-jargon-2.4.2.tar.bz2
foldc=https://web.archive.org/web/20140917131745/http://abloz.com/huzheng/stardict-dic/dict.org/stardict-dictd_www.dict.org_foldoc-2.4.2.tar.bz2
merrian=https://web.archive.org/web/20140917131745/http://abloz.com/huzheng/stardict-dic/dict.org/stardict-merrianwebster-2.4.2.tar.bz2
dictpath=/usr/share/stardict/dic
i=1
@asamountain
asamountain / App.js
Created January 6, 2020 10:35
App.js for react-gtm-module
import React from 'react';
import ReactDOM from 'react-dom';
import {Router} from 'react-router-dom';
import './index.css';
import App from './App';
import {createBrowserHistory} from 'history';
import TagManager from 'react-gtm-module'
const history = createBrowserHistory();
const tagManagerArgs = {
@asamountain
asamountain / puppeteer-get-metrics.js
Created January 6, 2020 04:19
get matric time for debugging in puppeteer
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
// Emitted when the DOM is parsed and ready (without waiting for resources)
page.once('domcontentloaded', () => console.info('✅ DOM is ready'));
// Emitted when the page is fully loaded
@asamountain
asamountain / cluster.js
Created January 4, 2020 09:36
puppeteer-cluster for heroku deploy
const cluster = await Cluster.launch({
concurrency: Cluster.CONCURRENCY_CONTEXT,
maxConcurrency: 3,
puppeteerOptions: {
headless: true,
args: ['--no-sandbox']
}
});
@asamountain
asamountain / scrolling-down.js
Created January 4, 2020 09:18
Puppeteer auto scrolling down for infinite element( puppeteer required )
await page.evaluate(async() => {
await new Promise((resolve, reject) => {
var totalHeight = 0;
var distance = 100;
var timer = setInterval(() => {
var scrollHeight = document.body.scrollHeight;
window.scrollBy(0, distance);
totalHeight += distance;
if (totalHeight >= scrollHeight) {
@asamountain
asamountain / index.js
Created January 4, 2020 08:47
Server side implement with Puppeteer-cluster
var express = require('express');
var router = express.Router();
const millieCrawler = require('../crawler/millie');
const ridiCrawler = require('../crawler/ridi');
const yesCrawler = require('../crawler/yes');
const {Cluster} = require('puppeteer-cluster');
/* GET home page. */
router.get('/', function (req, res) {
res.send('Home page opened up!');
@asamountain
asamountain / setupProxy.js
Last active January 1, 2020 12:58
When React proxy in package.json doesn't work, use 'http-proxy-middleware'
const proxy = require('http-proxy-middleware');
module.exports = function (app) {
app.use(proxy('/search', {target: 'http://localhost:8000/'}));
}
@asamountain
asamountain / package.json(nodejs root)
Created January 1, 2020 05:19
nodeJs(Express) server struggled to connect its proxy with view of ReactJs class. and this is the solution https://stackoverflow.com/a/52620241/9422917
"scripts": {
"client": "npm start --prefix ./client",
"server": "nodemon server.js",
"dev": "concurrently \"npm run server\" \"npm run client\""
}
@asamountain
asamountain / _document.js
Created December 23, 2019 03:23
practical way to set up Google Analytics Verification in nextJs
import App, { Container } from 'next/app'
import Router from 'next/router'
import React from 'react'
import withGA from 'next-ga'
import keys from '../config/keys'
class MyApp extends App {
static async getInitialProps({ Component, router, ctx }) {
let pageProps = {}
if (Component.getInitialProps) {
pageProps = await Component.getInitialProps(ctx)
import * as React from 'react'
import matter from "gray-matter";
import ReactMarkdown from "react-markdown";
import Disqus from 'disqus-react';
// components
import Layout from '../../components/Layout'
export default function BlogTemplate(props) {
function reformatDate(fullDate) {