Skip to content

Instantly share code, notes, and snippets.

View YaronMiro's full-sized avatar

Yaron YaronMiro

  • Israel
View GitHub Profile
@YaronMiro
YaronMiro / fetch-wrapper.js
Last active September 12, 2022 17:39
Fetch API Wrapper
class FetchWrapper {
constructor(baseURL) {
this._baseURL = baseURL ;
}
get baseURL (){
return this._baseURL ;
}
@YaronMiro
YaronMiro / escape-all-quotes.js
Created December 16, 2021 16:20
Escape all quotes (single or double), text may include such characters. Good for dynamic text for HTML attributes.
// We have 2 capture groups of each quote type, and than replace each on with
"h\"ell'o there".replace(/(")|(')/g, '\\$1$2');
const escapeHtml = (unsafeText) => {
return unsafeText
.replaceAll('&', '&')
.replaceAll('<', '&lt;')
.replaceAll('>', '&gt;')
.replaceAll('"', '&quot;')
@YaronMiro
YaronMiro / map-shallow-clone.js
Created December 5, 2021 22:45
Clone JS Map - Shallow
export const cloneMapShallow = (originalMap) => {
return [...originalMap.keys()].reduce(
(cloneMap, key) => cloneMap.set(key, originalMap.get(key)),
new Map()
);
};
@YaronMiro
YaronMiro / regex-Hebrew.js
Created October 9, 2018 12:43
JS regex Hebrew characters (Allowed also space (' ') and dash ('-') )
const onlyHebrewPattern = new RegExp(/^[\u0590-\u05FF ,.'-]+$/i);
const isValid = onlyHebrewPattern.test(value);
@YaronMiro
YaronMiro / Hebrew.php
Created May 23, 2018 13:11
Hebrew characters validation
<?php
// validate that the provider name contians only "hebrew" characters.
if (!preg_match("/^\p{Hebrew}+$/u", str_replace(' ', '', $element['#value']))) {
$error_message = t('שם ספק יכול להכיל אך ורק תווים בעברית');
form_set_error($element['#name'], $error_message);
}
@YaronMiro
YaronMiro / valid_phone.php
Created May 15, 2018 05:08
PHP Israeli phone number validation
<?php
class ValidationsService {
public static function isValidPhoneNumber($val) {
$pattern = "/^((\+972|972)|0)( |-)?([1-468-9]( |-)?\d{7}|(5|7)[0-9]( |-)?\d{7})$/";
return preg_match($pattern, $val);
}
}
@YaronMiro
YaronMiro / Docker.CheetSheet.Commands.md
Last active November 12, 2017 06:43
Docker Cheetsheet

DockerCommands

Bash

  • Run a container with a default bash command.

    Example:

    docker container run -it --name container_name ubuntu bash

    Description:

docker container run [OPTIONS] --name CONTAINER_NAME ubuntu COMMAND

@YaronMiro
YaronMiro / regex-symbols
Created March 26, 2016 11:25
Regular expressions
# Represent any number
\d
# Anything but a number
\D
# Represent any space
\s
# Anything but a space