Skip to content

Instantly share code, notes, and snippets.

View RomiC's full-sized avatar

Roman Charugin RomiC

  • Smolyan, Bulgaria
  • 08:37 (UTC +02:00)
View GitHub Profile
@RomiC
RomiC / http.mock.js
Created March 23, 2023 11:41
NodeJS Http(s) module mock for unit tests
import { EventEmitter } from 'node:events';
function createHttpModuleMock() {
const _requests = [];
const mockInstance = {
request(url, options, callback) {
return _requests[_requests.push(new HttpRequestMock(url, options, callback)) - 1];
},
get _lastRequest() {
@RomiC
RomiC / commit-msg
Last active March 13, 2023 07:44
An example of commit-hoot to check spell of the commit message via LanguageTool service
#!/bin/bash
# This script check the spell of your commit message saving
# using LanguageTool service (https://languagetool.org/).
#
# To use it, you register an account in LanguageTool service,
# than go to "Settings -> Account -> Access Tokens" and click
# "Create Integration Key". Copy your email and key and paste
# them into this scrip into the corrsponsing variables (LT_EMAIL,
# LT_API_KEY).
@RomiC
RomiC / coverage-diff.sh
Created March 12, 2023 07:24
Bash script to calculate (jest) test coverage diff
#!/bin/bash
# Output sample
# ========================= Total coverage diff summary ==========================
# lines : +0.46% ( +33 )
# statements : +0.49% ( +36 )
# functions : +0.66% ( +17 )
# branches : +0.16% ( +4 )
# ================================================================================
@RomiC
RomiC / vscode_when_conditions_list.txt
Created February 27, 2020 06:49
VSCode keybindings "when"-conditions list (includes some plugins)
acceptSuggestionOnEnter
accessibilityHelpWidgetVisible
accessibilityModeEnabled
activeEditor == 'WebviewEditor'
activeEditor == 'workbench.editor.extension'
activeEditorGroupEmpty
activePanel == 'refactorPreview'
atEndOfWord
breadcrumbsActive
breadcrumbsPossible
@RomiC
RomiC / form-column.tsx
Created November 1, 2019 09:31
React Form Component
import React, {PureComponent, ReactNode, ReactNodeArray} from 'react';
import {
formColumn12,
formColumn2,
formColumn3,
formColumn4,
formColumn5,
formColumn6,
formColumn8,
rightFormColumn
@RomiC
RomiC / Pagination.tsx
Created October 17, 2019 07:22
Pafination React component
import range from 'degiro-frontend-core/lib/utils/range';
import React, {PureComponent} from 'react';
import {NavLink} from 'react-router-dom';
import {paginationLink, paginationLinkActive, paginationList, paginationListItem} from './pagination.css';
interface PaginationProps {
/**
* Total amount of items
*/
itemsTotal: number;
@RomiC
RomiC / geo-distance.js
Created September 13, 2019 07:35
Calc the distance in meters between two geo-points
function distance(p1, p2) {
// radius of the sphere (Earth) in meters
const rad = 6372795;
// coordinates of two points
const {lat: llat1, long: llong1} = p1;
const {lat: llat2, long: llong2} = p2;
// in radians
const lat1 = llat1 * Math.PI / 180;
@RomiC
RomiC / pluralize.js
Last active January 10, 2019 09:07
Simple pluralize function for Russian language
function pluralize(quantity, options) {
/**
* options: [
* 0 -> товар
* 1 -> товара
* 2 -> товаров
* ]
*/
const remainder = (quantity %= 100, quantity > 14 ? quantity % 10 : quantity);
return options[remainder === 1 ? 0 : remainder > 1 && remainder < 5 ? 1 : 2];
@RomiC
RomiC / chrome-dev.bat
Last active February 4, 2020 11:06
Run Chrome with remote-debugging option
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --user-data-dir="C:\Users\roman.charugin\AppData\Roaming\Google\Chrome\User Data" --remote-debugging-port=9222 --no-first-run --no-default-browser-check --auto-open-devtools-for-tabs
@RomiC
RomiC / human-readable-size.ts
Created November 6, 2018 14:11
Format size in human-readable way
/**
* Format size in bytes in a human-readable way
* Examples:
* - humanReadableBytes(9708) → "9.48 KB"
* - humanReadableBytes(9708098213) → "9.04 GB"
* @param bytes Amount in bytes
* @return Formatted price
*/
function humanReadableSize(bytes: number): string {
const names: string[] = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];