Skip to content

Instantly share code, notes, and snippets.


Dmitriy Zyuzin dmitriyzyuzin

View GitHub Profile
dmitriyzyuzin / server.js
Created February 22, 2023 16:22
Express server with adding HTTP headers
View server.js
const express = require('express');
const path = require('path');
const app = express()
const PORT = process.env.port || 4000
app.use((req, res, next) => {
res.setHeader('referrer-policy', 'strict-origin-when-cross-origin');
dmitriyzyuzin /
Created November 14, 2021 21:11
TypeScript define custom property in window object

Declare ymaps property with TypeScript through typings.d.ts file (in the /src folder):

export declare global {
    interface Window {
        ymaps: {
            ready: Function,
dmitriyzyuzin / gist:a4ffa55c6a35ff19021c913bdbbbecf7
Created October 8, 2021 09:05
Another way to fix CORS errors
View gist:a4ffa55c6a35ff19021c913bdbbbecf7

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

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

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

dmitriyzyuzin / base64-converter.js
Created October 5, 2021 14:01
Load image and convert to base64
View base64-converter.js
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
dmitriyzyuzin / firestore.js
Created August 4, 2021 20:22
Save data to firebase (firestore)
View firestore.js
const firebase = require('firebase');
// firebase DB
const firebaseConfig = {
apiKey: '',
authDomain: '',
projectId: "",
storageBucket: "",
messagingSenderId: "",
dmitriyzyuzin /
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 => === === index)
dmitriyzyuzin /
Last active April 1, 2021 18:54
Useful commands
  1. du -shc * | sort -h - показывает сколько места занимает каждая директория
dmitriyzyuzin /
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" in my case)
  2. Modify your script:
const browser = await puppeteer.launch({
    executablePath: '/Applications/Google Chrome',
    args: ['--disable-blink-features=AutomationControlled'],
 headless: false,
dmitriyzyuzin /
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 /
Last active June 26, 2021 16:12
Docker cheat sheat


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: