Skip to content

Instantly share code, notes, and snippets.

View abramovantonru's full-sized avatar

Abramov Anton abramovantonru

  • Russia
View GitHub Profile
<?php declare(strict_types=1);
use Swift_Events_SendEvent;
use Swift_Events_SendListener;
use Swift_Plugins_Sleeper;
/**
* Plugin for fix timeout errors on sending mails from message queue (rabbitMQ) with persistent connection to SMTP server
*/
class Swift_Plugins_Timeout_Plugin implements Swift_Events_SendListener, Swift_Plugins_Sleeper
@abramovantonru
abramovantonru / SimpleStorage.js
Last active May 30, 2017 14:17
javascript (pure) logic for localStorage of browser
window.SimpleStorage = (function () {
const storageName = 'tmpName';
return{
get: function (id) {
var storage = localStorage.getItem(storageName);
if(storage)try {
storage = JSON.parse(storage);
return typeof storage[id] !== 'undefined' ? storage[id] : null;
} catch (e) {
return null;
@abramovantonru
abramovantonru / func.php
Last active January 26, 2017 12:15
get buffer of component template {template, php, bitrix, func}
<?
/**
* Get buffer of bitrix component template
* @param CBitrixComponent $component
* @param CBitrixComponent $arParams
* @return string $template
*/
function getTemplate(&$component, &$arParams){
ob_start();
if($arParams['TEMPLATE'] == 'LIST')
@abramovantonru
abramovantonru / mergeFormData.js
Last active December 17, 2016 14:33
merge form data on js {js, form, serialize, merge}
/**
* Get data from many forms
* Work in IE11+ and work with file ajax upload
*/
var
data = new FormData($('#form1')[0]),
form_2 = $('#form2').serializeArray();
form_2.forEach(function(fields){
data.append(fields.name, fields.value);
@abramovantonru
abramovantonru / sort.js
Created November 8, 2016 17:58
natural sort strings and numbers {js, sort, func}
function naturalSort(stringArray) {
var xor = function(a, b) {
return a ? !b : b;
};
var isDigit = function(chr) {
var charCode = function(ch) {
return ch.charCodeAt(0);
};
var code = charCode(chr);
return (code >= charCode('0')) && (code <= charCode('9'));
@abramovantonru
abramovantonru / script.js
Last active January 18, 2017 15:38
get random integer by min and max range {js, func, rnd}
function rand(min, max) { // get random integer by min and max range
return Math.floor(Math.random() * (max - min)) + min;
}