Skip to content

Instantly share code, notes, and snippets.

View corocoto's full-sized avatar
👨‍💻
creates something cool

Artem Gusev corocoto

👨‍💻
creates something cool
View GitHub Profile
@corocoto
corocoto / index.js
Created February 4, 2023 18:53
RSA key pair generator
const fs = require('fs');
const crypto = require('crypto');
function generateKeyPair() {
const keyPair = crypto.generateKeyPairSync('rsa', {
modulusLength: 4096,
publicKeyEncoding: {
type: 'pkcs1',
format: 'pem'
},
@corocoto
corocoto / consonants.js
Created November 25, 2021 17:03
find vowels and consonants
/[b-df-hj-np-tv-z]+/.test(str)
@corocoto
corocoto / uppercase.js
Created November 18, 2021 06:52
Uppercase first letter for the words by regexp
'sHoRt AnD sToUt'.toLowerCase().replace(/(^\w{1})|(\s+\w{1})/g, letter => letter.toUpperCase())
@corocoto
corocoto / jest.setup.js
Created October 30, 2021 14:06
strict test checking
/*
* Добавляет большей строгости при прогонке тестов.
* Если в .then или .catch проверка вернула ложный реузльтат, тогда тест упадет.
*
* Раньше текст проходили в блоках then и catch, даже если они падали.
* */
process.on('unhandledRejection', (error) => {
fail(error);
});
@corocoto
corocoto / macos-autocomplete.md
Created August 12, 2021 16:15
autocomplete for mac os terminal
  1. Open up your terminal
  2. Enter the command nano ~/.inputrc
  3. Paste the following commands one at a time:
set completion-ignore-case on
set show-all-if-ambiguous on
TAB: menu-complete
  1. Hit control+O to save changes to .inputrc followed by control+X to exit nano.
  2. Open a new Terminal window or tab
// Next `useEffect` hooks will be working the same
useEffect(() => {
const id = setInterval(() => {
setCount(count + 1)
}, 1000)
return () => clearInterval(id)
}, [count])
@corocoto
corocoto / index.js
Created January 30, 2021 10:45
Creating download link that contains various ASCII codes (created by TypedArray)
function typedArrayToURL(typedArr, mimeType) {
return URL.createObjectURL(new Blob([typedArr.buffer], {type: mimeType}));
}
const bytes = new Uint8Array(59);
for(let i = 0; i < 59; i++) {
bytes[i] = 32 + i;
}
const url = typedArrayToURL(bytes, 'application/octet-binary');
@corocoto
corocoto / index.js
Last active January 30, 2021 10:42
Creaing URL that display various ASCII codes (created by TypedArray)
function typedArrayToURL(typedArr, mimeType) {
return URL.createObjectURL(new Blob([typedArr.buffer], {type: mimeType}));
}
const bytes = new Uint8Array(59); // you can change this value and calculating bellow for dispalying another/additional ASCII codes
for(let i = 0; i < 59; i++) {
bytes[i] = 32 + i;
}
const url = typedArrayToURL(bytes, 'text/plain');
@corocoto
corocoto / server.js
Created January 8, 2021 16:20
HTTP Caching by using serve-static package
/**
* Docs about `serve-static` package: https://expressjs.com/en/resources/middleware/serve-static.html#setheaders
* Link on full Glitch project and article about HTTP caching: https://web.dev/codelab-http-cache/
*/
const express = require('express');
const app = express();
app.use(express.static('public', {
etag: true,
lastModified: true,
@corocoto
corocoto / heapsAlgorithm.js
Created January 7, 2021 11:05
The solution of the task https://leetcode.com/problems/permutations/ by using Heap's Algorithm
/**
* Link on the task: https://leetcode.com/problems/permutations/
* Description: Given an array nums of distinct integers, return all the possible permutations. You can return the answer in any order.
* Example:
* Input: nums = [1,2,3]
* Output: [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]
*/
const permute = function(nums) {
return (function permutationHeap(array, n, res = []) {