Skip to content

Instantly share code, notes, and snippets.

View dmitriyzyuzin's full-sized avatar

Dmitriy Zyuzin dmitriyzyuzin

View GitHub Profile
@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 / 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 / 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" />
@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 / 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 / compare-two-one-dimensional-arrays.md
Last active April 25, 2019 11:37
Compare two one dimensional arrays

Compare two one dimensional arrays

isEqualOneDimensionalArrays (arr1, arr2) {
    if (arr1.length !== arr2.length) {
      return false
    }

    const sortedArr1 = arr1.sort()
 const sortedArr2 = arr2.sort()