Skip to content

Instantly share code, notes, and snippets.

View denysbutenko's full-sized avatar

Denys Butenko denysbutenko

View GitHub Profile
@denysbutenko
denysbutenko / ImagesPipeline.py
Last active December 11, 2015 19:28
Pipelines.py
from scrapy.contrib.pipeline.images import ImagesPipeline
from scrapy.exceptions import DropItem
from scrapy.http import Request
class MyImagesPipeline(ImagesPipeline):
def image_key(self, url):
image_guid = url.split('/')[-1]
return '%s.jpg' % (image_guid)
@denysbutenko
denysbutenko / list.py
Last active December 11, 2015 22:58 — forked from gumeniukcom/gist:1358881
Python: Списки
# Создание списков
List = [] # пустой список
List = [ 'hello', 5, [1,2,3] ] # список с вложенным списком
List[i] # индекс
@denysbutenko
denysbutenko / getGoods.pdoFetch.php
Last active December 12, 2015 01:28
getGoods with pdoFetch
<?php
$pdoFetch = $modx->getService('pdofetch','pdoFetch',$modx->getOption('pdotools.core_path',null,$modx->getOption('core_path').'components/pdotools/').'model/pdotools/',$scriptProperties);
if (!($pdoFetch instanceof pdoFetch)) return '';
$miniShop = $modx->getService('minishop','miniShop',$modx->getOption('core_path').'components/minishop/model/minishop/',array());
if (!($miniShop instanceof miniShop)) return '';
$where = array();
if (empty($templates) && $templates != '0') {$where['template'] = $modx->resource->template;}
else if (!empty($templates)){
$tids = explode(',', $templates);
<?php
//Воспользовавшись сниппетом getResourceField вывести данные поля нужного ресурса
//Код сниппета ajax:
// Откликаться будет ТОЛЬКО на ajax запросы
if ($_SERVER['HTTP_X_REQUESTED_WITH'] != 'XMLHttpRequest') {return;}
// сниппет будет обрабатывать не один вид запросов, поэтому работать будем по запрашиваемому действию
$action = $_POST['action'];
<?php
error_reporting(E_ERROR | E_WARNING | E_PARSE);
define('MODX_API_MODE', true);
require 'index.php';
// Включаем обработку ошибок
$modx->getService('error','error.modError');
$modx->setLogLevel(modX::LOG_LEVEL_INFO);
$modx->setLogTarget(XPDO_CLI_MODE ? 'ECHO' : 'HTML');
@denysbutenko
denysbutenko / modx-packages.php
Last active December 12, 2015 02:58
modx-packages install
<?php
/*
--------------------
Package installer for MODX Revolution
--------------------
Author: Jeroen Kenters <www.kenters.com>
First released: 2012-02-08
License: GNU GENERAL PUBLIC LICENSE Version 2, June 1991
*/
<?php
$id = $modx->resource->id;
$tpls = explode(',', $modx->getOption('minishop.goods_tpl'));
if (!isset($limit)) {$limit = 10;}
if (!isset($tpl)) {$tpl = 'tpl.msGoods.row';}
// Вносим ID просмотренных товаров
if (in_array($modx->resource->template, $tpls)) {
if (!isset($_SESSION['viewed'])) {
@denysbutenko
denysbutenko / modx-install.sh
Last active December 22, 2019 14:28
modx-install
#!/bin/bash
# MySQL root password
ROOTPASS="password"
TIMEZONE="Europe/Moscow"
MYSQLPASS=`< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c12`
SFTPPASS=`< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c12`
PASSWORD=`< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c12`
##############
@denysbutenko
denysbutenko / modx-update.sh
Created February 3, 2013 19:57
modx-update
#!/bin/bash
echo "Enter username"
read USERNAME
##############
echo "Updating MODx"
cd /var/www/$USERNAME/www/
@denysbutenko
denysbutenko / modx-remove.sh
Created February 3, 2013 19:57
removeplace
#!/bin/bash
ROOTPASS="password"
echo "Enter username to delete:"
read USERNAME
mysql -uroot --password=$ROOTPASS -e "DROP USER $USERNAME@localhost"
mysql -uroot --password=$ROOTPASS -e "DROP DATABASE $USERNAME"
rm -f /etc/nginx/sites-enabled/$USERNAME.conf
rm -f /etc/nginx/sites-available/$USERNAME.conf