Skip to content

Instantly share code, notes, and snippets.

View roman-murashov's full-sized avatar

Roman Murashov roman-murashov

  • Saint-Petersburg, Russia
View GitHub Profile
@roman-murashov
roman-murashov / mysql-json.md
Created November 23, 2017 12:24 — forked from iamvanja/mysql-json.md
JSON type in MySQL

JSON type in MySQL

MySQL 5.7 comes with a native JSON data type and a set of built-in functions to manipulate values of the JSON type. This document demonstrates the usage.

INSERT

-- raw json
INSERT INTO json_test 
  (name, attributes)
VALUES (
@roman-murashov
roman-murashov / CSV_Parser.php
Created November 23, 2017 12:17 — forked from johndavedecano/CSV_Parser.php
CSV to HTML Table, MYSQL, JSON and Array
<?php
/**
* CSV_parser
*
* @package
* @author Dave's Simple Project
* @copyright MESMERiZE
* @version 2012
* @access public
*/
@roman-murashov
roman-murashov / batch-download.php
Created November 23, 2017 11:43 — forked from yosko/batch-download.php
Batch download files from a list of URLs into your own server and ZIP it for a easier download to your computer.
<!doctype html>
<!--
PHP Batch Download Script
@author Yosko <contact@yosko.net>
@copyright none: free and opensource
@link http://www.yosko.net/article32/snippet-05-php-telechargement-de-fichiers-par-lots
-->
<html lang="en-US">
<head>
(function () {
'use strict'
const QUOTES = ['', "'", '"']
// const THRESHOLD = 0.95
// function levenstein(a, b) {
// const d = (i, j) => 0 === Math.min(i, j) ? Math.max(i, j) : Math.min(d(i - 1, j) + 1, d(i, j - 1) + 1, d(i - 1, j - 1) + (a[i - 1] === b[j - 1] ? 0 : 1))
// return d(a.length, b.length)
// }
// levenstein('kitten', 'sitting')
// function ratio(a, b) {
@roman-murashov
roman-murashov / showspreadsheet.php
Created August 18, 2017 12:37 — forked from pamelafox/showspreadsheet.php
PHP for parsing the JSON output a published Google spreadsheet and displaying columns from each row.
<?php
// Parsing this spreadsheet: https://spreadsheets.google.com/pub?key=0Ah0xU81penP1dFNLWk5YMW41dkcwa1JNQXk3YUJoOXc&hl=en&output=html
$url = 'http://spreadsheets.google.com/feeds/list/0Ah0xU81penP1dFNLWk5YMW41dkcwa1JNQXk3YUJoOXc/od6/public/values?alt=json';
$file= file_get_contents($url);
$json = json_decode($file);
$rows = $json->{'feed'}->{'entry'};
foreach($rows as $row) {
echo '<p>';
Управление альбомом галереи на странице ресурса
Tips & tricks
Чего мне всегда не хватало в Revo дак это удобной галереи для менеджера. Для Evo есть EvoGallery, где можно управлять альбомом прямо на странице документа. Менеджеру не нужно постоянно путаться, что редактирование документов осуществляется в дереве документов, а фотографии грузятся через модули. Все в одном месте, удобно. Причем галерея нужна на основе базы данных, а не просто файлы в папке, чтобы можно было указать описания для фотографий, метки, сортировать их итд.
Поэтому решил попытаться сделать похожее в Revo, где в качестве галереи выбрал Gallery. В Revo есть возможность создавать собственные параметры ввода для TV, на основе которых в Gallery сделан тип TV galleryalbumlist, с помощью которого можно привязать альбом к документы, но фотографии по прежнему загружаются через компоненты.
Создадим новый тип galleryalbumview. Принцип работы будет такой: TV хранит ID альбома в галерее, редактирования ID не будет. При редактировании документа проб
@roman-murashov
roman-murashov / FieldEditror.php
Created August 14, 2017 11:17 — forked from Burick/FieldEditror.php
Modx Revo Плагин добавляет редактор к указанным полям ресурса
<?php
/*
Плагин добавляет редактор к указанным полям ресурса
событие OnDocFormPrerender
*/
switch ($modx->event->name) {
case 'OnDocFormPrerender':
if (!$modx->controller->resourceArray) {
return;
}
@roman-murashov
roman-murashov / change_templates
Created August 14, 2017 11:15 — forked from alexburma/change_templates.php
Modx Revo (auto-change templates)
<?php
$resources = $modx->getCollection('modResource',array('parent' => 1)); //1 is id of parent container
foreach ($resources as $res) {
$res->set('template', 2); // 2 is id of template
$res->save();
}
@roman-murashov
roman-murashov / cloneResource.php
Created August 14, 2017 11:09 — forked from sepiariver/cloneResource.php
A Snippet to clone a Resource into multiple, user-defined parent containers in arbitrary contexts
<?php
// get user-defined source document and target parents
$source = intval($modx->getOption('sourceId', $scriptProperties, ''));
$targets = array_map('trim', explode(',', $modx->getOption('targetIds', $scriptProperties, '')));
// to prevent accidents...
$_allowedUsers = explode(',', 'username1,username2');
// check stuff, and if passed then get the source document object
if ( !in_array($modx->user->get('username'), $_allowedUsers) || empty($source) || $source == 0 || !is_array($targets) || empty($targets) ) return;
$sourceDoc = $modx->getObject('modResource', $source);