Skip to content

Instantly share code, notes, and snippets.

Erasmo Marín erasmo-marin

  • Cornershop
  • Chile
Block or report user

Report or block erasmo-marin

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View babel-preset-env-example.json
{
"presets": [
["env", {
"targets": {
"browsers": ["last 2 versions", "safari >= 7"]
}
}]
]
}
View importMomentLocales.js
import 'moment/locale/es';
import 'moment/locale/pt';
View ignorePlugin.js
// Moment.js is an extremely popular library that bundles large locale files
// by default due to how Webpack interprets its code. This is a practical
// solution that requires the user to opt into importing specific locales.
// https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
// You can remove this if you don't use Moment.js:
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/)
View dynamicImportExample.jsx
const Sidebar = dynamicComponent(() =>
import(/* webpackChunkName: "Sidebar" */ './components/sidebar')
);
View dynamicComponent.jsx
import React, { Component } from 'react';
export default function dynamicComponent(importComponent) {
class DynamicComponent extends Component {
constructor(props) {
super(props);
this.state = {
component: null
};
View middleware.js
import detector from "spider-detector";
import url from "url";
app.use(detector.middleware());
app.get("*", function(req, res, next) {
//we only serve static snapshots to spiders
if(!req.isSpider() ) {
next();
View crawlerMain.js
async function fetchAllPages() {
const domain = "https://mycooleebsite.com";
const pages = [
"/",
"/about",
"/pricing",
"/contact"
]
const browser = await puppeteer.launch({ args: ["--no-sandbox"] });
View crawler2.js
import puppeteer from "puppeteer";
async function crawler({ url, browser }) {
let page = null;
let html = false;
try {
page = await browser.newPage();
//networkidle0: consider navigation to be finished when
//there are no more than 2 network connections for at least 500 ms.
View saveToFile.js
import fsPath from "fs-path";
const saveUrlToFile = ({ html = "", pathName = "/", output = "." }) => {
const path = pathName == "/"
? `${output}/index.html`
: `${output}${pathName}.html`;
fsPath.writeFile(path, html, err => {
if (err) {
View crawler1.js
import puppeteer from "puppeteer";
async function crawler({ url }) {
const browser = await puppeteer.launch({ args: ["--no-sandbox"] });
let page = null;
let html = false;
try {
page = await browser.newPage();
You can’t perform that action at this time.