Skip to content

Instantly share code, notes, and snippets.

View dmitriyzyuzin's full-sized avatar

Dmitriy Zyuzin dmitriyzyuzin

View GitHub Profile
@dmitriyzyuzin
dmitriyzyuzin / browserslist.md
Last active March 2, 2021 15:11
How to fix regeneratorRuntime is not defined

Add line "browserslist": ["since 2017-06"] to your package.json file. Babel won't add polyfills for async/await, es6. So you don't need to install and add reneneratorRuntime (or babel-polyfill) to your bundle!

@dmitriyzyuzin
dmitriyzyuzin / puppeteer.md
Created February 3, 2021 11:45
Run Puppeteer with your local chrome browser (not Chromium)

How to run puppeteer tests with your local Chrome browser

  1. Find browser's executable path:
    Go to chrome://version/ (inside Chrome browser) and find "Executable Path" variable ("/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" in my case)
  2. Modify your script:
const browser = await puppeteer.launch({
    executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
    args: ['--disable-blink-features=AutomationControlled'],
 headless: false,
@dmitriyzyuzin
dmitriyzyuzin / index.js
Created December 16, 2020 11:40
JavaScript Fetch handle 204 http status
async function getJSON(response) {
if (response.status === 204) return '';
return response.json();
}
@dmitriyzyuzin
dmitriyzyuzin / server.js
Created December 4, 2020 15:51
Simple NodeJS Express server with CORS and pre-flyght
const express = require('express')
const cors = require('cors')
const bodyParser = require("body-parser")
const app = express()
const PORT = process.env.port || 4000
// to parse req.body for POST-requests
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
@dmitriyzyuzin
dmitriyzyuzin / walk.js
Created November 20, 2020 10:37
Recursively walk through directory
async function walk(dir) {
let files = await fs.readdir(dir)
files = await Promise.all(files.map(async file => {
const filePath = path.join(dir, file)
const stats = await fs.stat(filePath)
if (stats.isDirectory()) {
return walk(filePath);
}
else if (stats.isFile()) {
return filePath;
@dmitriyzyuzin
dmitriyzyuzin / quick-http-servers.md
Last active November 14, 2020 14:29
Easy web-servers

Quick servers

Python

user@user-pc:~$ python3 -m http.server 8000
user@user-pc:~$ python -m SimpleHTTPServer 8000
@dmitriyzyuzin
dmitriyzyuzin / vs-code-params.txt
Last active November 14, 2020 14:28
Visual Studio Code params
{
"workbench.startupEditor": "none",
"workbench.statusBar.feedback.visible": false,
"window.menuBarVisibility": "toggle",
"workbench.statusBar.visible": false,
"workbench.activityBar.visible": false,
"editor.fontFamily": "JetBrains Mono, Menlo, Monaco, 'Courier New', monospace",
"editor.fontSize": 14,
"editor.fontLigatures": true,
"editor.lineHeight": 24,
@dmitriyzyuzin
dmitriyzyuzin / next.config.js
Created January 17, 2020 10:18
next.js config example
const withImages = require("next-images");
const nextConfig = {...}
module.exports = (phase) => {
if (phase === PHASE_DEVELOPMENT_SERVER || phase === PHASE_PRODUCTION_BUILD) {
const withCSS = require("@zeit/next-css");
return withCss(withImages(nextConfig)))));
}
return withImages(nextConfig);
};
@dmitriyzyuzin
dmitriyzyuzin / jest-cheet-sheet.md
Last active July 1, 2019 12:04
Jest cheat-sheet
  1. Run single test
node <path-to-jest> -i <you-test-file> -c <jest-config> -t "<test-block-name>"
@dmitriyzyuzin
dmitriyzyuzin / change_submit_btn_text.md
Created May 29, 2019 15:06
Iphone change submit button text from "Go" to "Search"

Change Iphone submit button text from "Go" to "Search"

You need create form and at least one input element. Required:

  1. input with type="search"
  2. define attribute "action" at form
<form action="">
	<input type="search" name="q" aria-label="Search" />