Skip to content

Instantly share code, notes, and snippets.

View dmitriyzyuzin's full-sized avatar

Dmitriy Zyuzin dmitriyzyuzin

View GitHub Profile
@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 / 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 / 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 / fetch-handle-response.md
Last active March 2, 2021 15:14
Handle response using Fetch

Fetch handle response

Variant 1

const requestOptions = {
    mode: 'cors',
    headers: {
      'Content-Type': 'application/json',
      'Access-Control-Allow-Origin': '*'
    }
@dmitriyzyuzin
dmitriyzyuzin / bash.md
Last active April 1, 2021 18:54
Useful commands
  1. du -shc * | sort -h - показывает сколько места занимает каждая директория
@dmitriyzyuzin
dmitriyzyuzin / index.md
Created April 29, 2021 17:55
Filter array of objects by property value

arr - array of objects
id - filter value

arr.filter((item, index, arr) => arr.findIndex(_item => _item.id === item.id) === index)
@dmitriyzyuzin
dmitriyzyuzin / docker.md
Last active June 26, 2021 16:12
Docker cheat sheat

Docker

Building an image

Note: don't forget to create a Dockerfile in the same directory. Next command build new php-obfuscator image from current directory:

docker build -t php-obfuscator .

How to verify? Next command should print info about new image:

@dmitriyzyuzin
dmitriyzyuzin / firestore.js
Created August 4, 2021 20:22
Save data to firebase (firestore)
const firebase = require('firebase');
require('firebase/firestore');
// firebase DB
const firebaseConfig = {
apiKey: '',
authDomain: '',
projectId: "",
storageBucket: "",
messagingSenderId: "",
@dmitriyzyuzin
dmitriyzyuzin / base64-converter.js
Created October 5, 2021 14:01
Load image and convert to base64
const loadIconAndConvertIconToBase64 = url => {
return fetch(url)
.then(response => response.blob())
.then(blob => new Promise((resolve, reject) => {
const reader = new FileReader()
reader.onloadend = () => resolve(reader.result)
reader.onerror = reject
reader.readAsDataURL(blob)
}));
}
@dmitriyzyuzin
dmitriyzyuzin / gist:a4ffa55c6a35ff19021c913bdbbbecf7
Created October 8, 2021 09:05
Another way to fix CORS errors

Пример, нужно дернуть какую-то стороннюю апиху https://my-awesome-api.haha CORS настроен таким образом что ты не можешь это сделать со стороннего домена, а доступа к серверу апихи нет (сторонеее апи же). То можно использовать прокси-сервер для этого. CORS реализованы в браузере только.

npx local-cors-proxy --proxyUrl https://my-awesome-api.haha

Это тулза выдаст примерно следующее: