Skip to content

Instantly share code, notes, and snippets.

@iredun
iredun / pre.php
Created August 22, 2015 21:28
Функция для распечатки массива, с выводом дебаг информации
<?
function pre($array=false,$description=false,$debug_print_trace=false) {
$debug_trace = debug_backtrace();
if($debug_print_trace){
foreach(debug_backtrace() as $k=>$v){
if($v['function'] == "include" || $v['function'] == "include_once" || $v['function'] == "require_once" || $v['function'] == "require"){
$backtracel .= "#".$k." ".$v['function']."(".$v['args'][0].") called at [".$v['file'].":".$v['line']."]<br />";
}else{
$backtracel .= "#".$k." ".$v['function']."() called at [".$v['file'].":".$v['line']."]<br />";
}
@iredun
iredun / code39.php
Created October 23, 2015 12:29
Генерирует штрих-код формата CODE 39, Пример использования www.example.com/code39.php?str=21010100745&width=400&height=200
<?
header ("Content-type: image/png");
$code = array();
$code['start'] = '1001011011010';
$code['1'] = '110100101011';
$code['2'] = '101100101011';
$code['3'] = '110110010101';
$code['4'] = '101001101011';
$code['5'] = '110100110101';
$code['6'] = '101100110101';
@iredun
iredun / arrayToXML.php
Created October 26, 2015 07:45
Array to Xml
<?php
header("Content-Type: text/xml");
$array = array (
'10.10.10.10' => 'Server'
);
$xml = new SimpleXMLElement('<root/>');
array_walk_recursive($array, array ($xml, 'addChild'));
print $xml->asXML();
?>
@iredun
iredun / delDirRecursive.php
Created October 29, 2015 07:26
Функция для удаления директорий с вложенными файлами, возвращает 1 если удаление прошло успешно.
<?
function delTree($dir)
{
$files = array_diff(scandir($dir), array('.','..'));
foreach ($files as $file) {
(is_dir("$dir/$file")) ? delTree("$dir/$file") : unlink("$dir/$file");
}
return rmdir($dir);
}
?>
@iredun
iredun / copy_table.sql
Created December 14, 2015 14:29
Cкопировать таблицу в MySQL
CREATE TABLE new_table_name LIKE old_table_name;
INSERT new_table_name SELECT * FROM old_table_name;
@iredun
iredun / youtube.txt
Created April 13, 2016 08:59
Youtube API get thumbnail image
Each YouTube video has 4 generated images. They are predictably formatted as follows:
http://img.youtube.com/vi/<insert-youtube-video-id-here>/0.jpg
http://img.youtube.com/vi/<insert-youtube-video-id-here>/1.jpg
http://img.youtube.com/vi/<insert-youtube-video-id-here>/2.jpg
http://img.youtube.com/vi/<insert-youtube-video-id-here>/3.jpg
The first one in the list is a full size image and others are thumbnail images. The default thumbnail image (ie. one of 1.jpg, 2.jpg, 3.jpg) is:
http://img.youtube.com/vi/<insert-youtube-video-id-here>/default.jpg
For the high quality version of the thumbnail use a url similar to this:
@iredun
iredun / CentOS command.txt
Last active March 20, 2017 14:10
Команда которая находит и выводи путь к файлу, номер строки и строку, в котором содержится "base64_decode" в текущем каталоге
grep -iRI -n "base64_decode" ./
@iredun
iredun / init.php
Last active January 18, 2017 12:15
Выводит инфоблоки в админке только текущего сайта (https://dev.1c-bitrix.ru/community/webdev/user/11948/blog/2692/)
<?
AddEventHandler('main', 'OnBuildGlobalMenu', 'ASDOnBuildGlobalMenu');
function ASDOnBuildGlobalMenu(&$aGlobalMenu, &$aModuleMenu)
{
$arSites = array(
'www.site.ru' => 's1',
'site.ru' => 's1',
);
$arIBsites = array();
@iredun
iredun / lvm.txt
Last active January 19, 2017 14:31
Как увеличить LVM раздел OS Linux CentOS Оригинал - https://anart.ru/server/2013/07/23/uvelichenie-diska-virtualbox-i-gostevoj-sistemyi-linux.html
Смотрим, что у нас имеется на данный момент из устройств/разделов
# fdisk -l
Диск /dev/sda: 21.5 ГБ, 21474836480 байт
...
Устр-во Загр Начало Конец Блоки Id Система
/dev/sda1 * 1 64 512000 83 Linux
/dev/sda2 64 653 4729856 8e Linux LVM
/dev/sda3 653 1305 5239532+ 8e Linux LVM
@iredun
iredun / export.php
Created January 21, 2017 16:57
Перенос пользовательских свойств 1С-Битрикс (с названиями + в обход тех которые уже есть)
<?php
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/header.php");
$APPLICATION->SetTitle("Export");
$arResult = array();
$rsData = CUserTypeEntity::GetList( array("ID"=>"ASC"), array("LANG" => "ru") );
while($arRes = $rsData->Fetch())
{
$ar_res = CUserTypeEntity::GetByID( $arRes['ID'] );
$arResult[] = $ar_res;
}