Skip to content

Instantly share code, notes, and snippets.

@eugenemtn
eugenemtn / validate-url.js
Created June 20, 2021 00:29
URL validator
function validURL(str) {
var pattern = new RegExp(
'^(https?:\\/\\/)?' + // protocol
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name
'((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path
'(\\?[;&a-z\\d%_.~+=-]*)?' + // query string
'(\\#[-a-z\\d_]*)?$',
'i',
); // fragment locator
@eugenemtn
eugenemtn / abbreviatedNumber.ts
Created March 8, 2021 15:16
Formatter for abbrevated numbers
export function abbreviatedNumber(value: number): string {
if (isNaN(value)) {
return "";
}
let newValue = value;
const suffixes = ["", "K", "M", "B", "T"];
let suffixNum = 0;
while (newValue >= 1000) {
newValue /= 1000;
suffixNum++;
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required
function clipBoardWriteValue(value, ref) {
// If we have the navigator.clipboard then it is possible to write a string to a clipboard directly
if (navigator.clipboard) {
navigator.clipboard.writeText(value)
.then(() => {
this.showCopiedBadge();
});
return;
}
// Otherwise, we need to select some node's content and run document.execCommand('copy')