Skip to content

Instantly share code, notes, and snippets.

View NewEXE's full-sized avatar
🌀
WIP

Vlad Voloshyn NewEXE

🌀
WIP
  • Sweet Stack Digital
  • Ukraine, Kharkiv
View GitHub Profile
@NewEXE
NewEXE / remove-docker-entities.sh
Created March 16, 2023 13:42
Remove all docker entities (containers, images, volumes, networks)
# Remove containers
docker rm -f $(docker ps -a -q)
# Remove images
docker rmi -f $(docker images -a -q)
# Remove volumes
docker volume rm $(docker volume ls -q)
docker volume prune
docker system prune --volumes
@NewEXE
NewEXE / spread-exclude.js
Created October 18, 2022 13:08
JS spread operator: exclude properties
// Example: exclude (separate) 'notifyUser' property from 'request' object
const request = {
id: 1,
title: 'ID 1 title',
notifyUser: true
};
const { notifyUser, ...updateSet } = request;
@NewEXE
NewEXE / get-enum-key.ts
Created July 6, 2022 12:42
Get enum key by value (Typescript)
export const getEnumKeyByValue = (enumerated, value: string) => {
return Object.keys(enumerated)[
Object.values(enumerated).indexOf(value as typeof enumerated)
];
};
@NewEXE
NewEXE / enum-to-array.ts
Last active April 12, 2022 19:02
Typescript Enum to Array
/** For key/value enum: */
export enum CountryEnum {
fra = 'FRANCE',
ukr = 'UKRAINE',
}
// ['FRANCE', 'UKRAINE']
export const CountryList = Object.entries(CountryEnum).map(
([, value]) => value,
);
@NewEXE
NewEXE / bombard-ru-propaganda.py
Last active March 22, 2022 20:17 — forked from Toyto/bomberman.py
Send bombard requests to russian propaganda and infrastructure sites.
# -*- coding: utf-8 -*-
# Send bombard requests to russian propaganda and infrastructure sites.
#
# Requirements: Docker, Python 2.7+, requests
#
# Check which pip version do you have: pip --version
# Then you need to install
# pip install requests
# OR
# sudo python3 -m pip install requests
@NewEXE
NewEXE / get-abbreviated-number.php
Last active January 7, 2022 00:23
Abbreviate large numbers (1000 -> 1K). Fast approach. PHP
<?php
/**
* Convert long integer number into abbreviated string.
* Fast approach without math functions usage.
* Integers up to 999 Uncentillions (1 Un = 1e306) are supported.
*
* getAbbreviatedNumber('1024'); // '1.02K'
* getAbbreviatedNumber('-123456', 3); // '-123.456K'
* getAbbreviatedNumber('1000000'); // '1M'
@NewEXE
NewEXE / remove-any-whitespace.php
Last active February 11, 2022 10:43
Remove any whitespace character
<?php
/**
* Removes any whitespace character.
* This includes tabs and newline characters, as well as
* multibyte whitespace such as the thin space and ideographic space,
* unprintable characters and invalid unicode characters.
*
* @param string $string
* @return string
@NewEXE
NewEXE / getRandNumber.php
Last active November 30, 2021 08:21
Fast and simple getRandNumber function (PHP)
<?php
$num = getRandNumber(5);
var_dump($num); // 5-digits number like 48149
/**
* Returns fixed-length random integer.
*/
function getRandNumber(int $length): int
@NewEXE
NewEXE / index.php
Last active May 12, 2020 10:00
PHP random funtion
<?php
// From old versions of Laravel
// Don't use in cryptography
function str_random($length = 16)
{
$pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
return substr(str_shuffle(str_repeat($pool, $length)), 0, $length);
}
@NewEXE
NewEXE / index.php
Last active August 18, 2021 23:55
Convert anything to string (PHP)
<?php
/**
* @param mixed $value Value of any PHP type.
* @return string Value as readable string.
*/
function toString($value, $compactArray = true): string
{
$data_type = '';
if (is_array($value)) {