Skip to content

Instantly share code, notes, and snippets.

View itorgov's full-sized avatar
🏠
Work at home

Ivan Torgov itorgov

🏠
Work at home
View GitHub Profile
@itorgov
itorgov / base64url.php
Last active March 6, 2020 10:30 — forked from nathggns/base64url.php
These two functions implement base64url functionality for PHP.
<?php
function base64url_encode($data) {
return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
}
function base64url_decode($data) {
return base64_decode(str_pad(strtr($data, '-_', '+/'), strlen($data) % 4, '=', STR_PAD_RIGHT));
}
@itorgov
itorgov / plural.js
Last active March 5, 2020 13:45 — forked from tomfun/plural.js
JavaScript plural function for Russian language.
function getNoun(number, one, two, five) {
let n = Math.abs(number);
n %= 100;
if (n >= 5 && n <= 20) {
return five;
}
n %= 10;
if (n === 1) {
return one;
}
@itorgov
itorgov / DateService.php
Last active March 6, 2020 10:29
Divide date interval to subintervals.
<?php
class DateService
{
const ONE_WEEK_INTERVAL = '+6 days';
const THIRTY_DAYS_INTERVAL = '+29 days';
const ONE_YEAR_INTERVAL = '+364 days';
/**
* This method get two dates (start and end of an interval) and length of every subinterval you need.