Skip to content

Instantly share code, notes, and snippets.

@d1i1m1o1n
d1i1m1o1n / snippets.cson
Last active March 3, 2016 12:36
PHP pre snippets from atom editor
# Your snippets
#
# Atom snippets allow you to enter a simple prefix in the editor and hit tab to
# expand the prefix into a larger code block with templated values.
#
# You can create a new snippet in this file by typing "snip" and then hitting
# tab.
#
# An example CoffeeScript snippet to expand log to console.log:
#
@d1i1m1o1n
d1i1m1o1n / module.js
Created January 7, 2016 08:02
Подробный обзор паттерна "модуль"
var Module = (function () {
// locally scoped Object
var myObject = {};
// declared with `var`, must be "private"
var privateMethod = function () {};
myObject.someMethod = function () {
// take it away Mr. Public Method
@d1i1m1o1n
d1i1m1o1n / script.js
Created December 26, 2015 09:14
Javascript function with callback
function a(b) {
console.log('a');
console.log('b');
b();
}
a(function() {
console.log('c');
});
@d1i1m1o1n
d1i1m1o1n / add_avatar.php
Last active April 2, 2016 13:34
Bitrix update user PERSONAL_PHOTO
<?
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");
global $USER;
if (!empty($_FILES['review_avatar']['tmp_name'])) {
$user = new CUser;
$res_user = $user->Update($USER->GetID(), array('PERSONAL_PHOTO' => $_FILES["review_avatar"]));
if($res_user) {
$res_user = '1';
@d1i1m1o1n
d1i1m1o1n / run.php
Created December 14, 2015 09:18
Bitrix create detail_picture and preview_picture from detail_picture
$arLoadProductArray = Array(
"ACTIVE" => "Y",
"IBLOCK_SECTION_ID" => $sectionId,
"IBLOCK_ID" => $iblockId,
"CODE" => translit($elementName).$sectionId,
"PROPERTY_VALUES" => $arProperties,
"NAME" => $elementName,
"PREVIEW_TEXT" => $elementPreviewText,
"DETAIL_TEXT" => $elementDetailText,
"DETAIL_PICTURE" => CFile::MakeFileArray($_SERVER["DOCUMENT_ROOT"]."/import_xls/КАРТИНКИ/".$elementDetailPicture)
@d1i1m1o1n
d1i1m1o1n / translit.php
Created December 11, 2015 13:44
Translit cyrillic to lat and replace cpases and symbols
function translit($str) {
$rus = array('А', 'Б', 'В', 'Г', 'Д', 'Е', 'Ё', 'Ж', 'З', 'И', 'Й', 'К', 'Л', 'М', 'Н', 'О', 'П', 'Р', 'С', 'Т', 'У', 'Ф', 'Х', 'Ц', 'Ч', 'Ш', 'Щ', 'Ъ', 'Ы', 'Ь', 'Э', 'Ю', 'Я', 'а', 'б', 'в', 'г', 'д', 'е', 'ё', 'ж', 'з', 'и', 'й', 'к', 'л', 'м', 'н', 'о', 'п', 'р', 'с', 'т', 'у', 'ф', 'х', 'ц', 'ч', 'ш', 'щ', 'ъ', 'ы', 'ь', 'э', 'ю', 'я');
$lat = array('A', 'B', 'V', 'G', 'D', 'E', 'E', 'Gh', 'Z', 'I', 'Y', 'K', 'L', 'M', 'N', 'O', 'P', 'R', 'S', 'T', 'U', 'F', 'H', 'C', 'Ch', 'Sh', 'Sch', 'Y', 'Y', 'Y', 'E', 'Yu', 'Ya', 'a', 'b', 'v', 'g', 'd', 'e', 'e', 'gh', 'z', 'i', 'y', 'k', 'l', 'm', 'n', 'o', 'p', 'r', 's', 't', 'u', 'f', 'h', 'c', 'ch', 'sh', 'sch', 'y', 'y', 'y', 'e', 'yu', 'ya');
$str = strtolower(str_replace($rus, $lat, $str));
return preg_replace("![^a-z0-9]+!i", "-", $str);
}
<?if(CModule::IncludeModule("sale"))
echo Number2Word_Rus(1425.43);?>
<?define("LOG_FILENAME", $_SERVER["DOCUMENT_ROOT"]."/log.txt");
AddMessage2Log('Моя мессага');?>
@d1i1m1o1n
d1i1m1o1n / bitrixOneClickOrder.php
Created December 8, 2015 12:44
Заказ в один клик Bitrix
<?php
require_once($_SERVER['DOCUMENT_ROOT']. "/bitrix/modules/main/include/prolog_before.php");
// добавление заказа в один клик, только по имени и телефону
CModule::IncludeModule("sale");
CModule::IncludeModule("catalog");
if(!empty($_REQUEST['name']) && !empty($_REQUEST['phone']))
{
$name = $_REQUEST['name'];
@d1i1m1o1n
d1i1m1o1n / update_count_in_cart.php
Created December 7, 2015 18:58
Bitrix update quantity (count) in cart (basket) for ajax request
<?
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");
CModule::IncludeModule("sale");
if (IntVal($_POST["id"]) > 0) {
CSaleBasket::Update($_POST["id"], array("QUANTITY" => $_POST["count"]));
}
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/epilog_after.php");