Skip to content

Instantly share code, notes, and snippets.

View wiedymi's full-sized avatar
:electron:
Working so hard...

Uladzislau Yakauleu wiedymi

:electron:
Working so hard...
View GitHub Profile
@wiedymi
wiedymi / ftp-dump.js
Last active June 27, 2022 20:21
Dump ftp folder (Node.js)
require('dotenv').config()
const ftp = require('ftp')
const fs = require('fs')
const { promisify } = require('util')
const env = {
host: process.env.FTP_HOST,
user: process.env.FTP_USER,
password: process.env.FTP_PASS,
folder: process.env.FTP_FOLDER || '/'
@wiedymi
wiedymi / rename_js_files.sh
Created March 4, 2022 07:45 — forked from afternoon/rename_js_files.sh
Rename .js files to .ts
find app/src -name "*.js" -exec sh -c 'mv "$0" "${0%.js}.ts"' {} \;
@wiedymi
wiedymi / mysql-dump.js
Last active May 31, 2021 06:02
Dump mysql database (json)
require('dotenv').config()
const { promisify } = require('util')
const mysql = require('mysql');
const fs = require('fs');
const db = {
database: process.env.DATABASE,
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASS,
function getGDriveEmbed(id) {
return `https://drive.google.com/file/d/${id}/preview`
}
function removeDublication(array, cb) {
if (!array) {
throw new Error("No array has been provided.");
}
if (!cb) {
throw new Error("No callback has been provided.");
}
return array.reduce(
(acc, value) => {
const isExist = acc.some(v => cb(v, value));
@wiedymi
wiedymi / translit.js
Last active January 3, 2020 07:16
Japanese Transliteration For Belarusian Language
/* eslint-disable no-fallthrough */
const JapaneseLatin = {
ba: "ба",
cha: "ця",
da: "да",
ga: "га",
ha: "ха",
ja: "дзя",
ka: "ка",
ma: "ма",
export const convertTime = (time): string => {
const date = new Date(+`${time}000`)
let hours = date.getHours()
let minutes = date.getMinutes()
const ampm = hours >= 12 ? 'PM' : 'AM'
hours = hours % 12
hours = hours ? hours : 12
minutes = minutes < 10 ? '0' + minutes : minutes
const strTime = hours + ':' + minutes + ' ' + ampm
export const bytesToSize = (bytes, decimals = 2): string => {
if (bytes === 0) return '0 Bytes'
const k = 1024
const dm = decimals < 0 ? 0 : decimals
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
const i = Math.floor(Math.log(bytes) / Math.log(k))
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i]
@wiedymi
wiedymi / nFormetter.ts
Last active December 12, 2019 12:03
nFormatter.ts
export function nFormatter(num, digits = 4): string {
const si = [
{ value: 1, symbol: '' },
{ value: 1e3, symbol: 'K' },
{ value: 1e6, symbol: 'M' },
{ value: 1e9, symbol: 'G' },
{ value: 1e12, symbol: 'T' },
{ value: 1e15, symbol: 'P' },
{ value: 1e18, symbol: 'E' },
]
@wiedymi
wiedymi / drive.js
Last active November 15, 2019 13:18
getGoogleDriveEmbedLink From Array Of Shared Links
'use strict'
const fs = require('fs');
function getGoogleDriveEmbedLink(links = ``, nameFile = 'output.txt'){
links = links
.split('\n')
.map(link => link.toString().replace('https://drive.google.com/open?id=',''))
.map(hash => `https://drive.google.com/file/d/${hash}/preview`)
.reduce((output, input, index) => {
return output += `\n${index + 1} | ${input}`;