Skip to content

Instantly share code, notes, and snippets.

View vanchelo's full-sized avatar
💭
Life is good

Brezhniev Ivan vanchelo

💭
Life is good
View GitHub Profile
@vanchelo
vanchelo / gist:3059790
Created July 6, 2012 12:07
Pagebreaker
<?php
if ($modx->Event->name == 'OnPageNotFound') {
$uri = $_SERVER['REQUEST_URI'];
// Обычный ресурс
if (preg_match("#(\.*?[a-z0-9_\-]+)_p(\d+)\.html#si", $uri, $m)) {
$alias = preg_replace("#(\.*?[a-z0-9_\-]+)_p(\d+)(\.html)#si", "$1$3", $uri);
$alias = substr($alias, 1, strlen($alias));
}
// Контейнер
@vanchelo
vanchelo / chmod_site.sh
Created September 8, 2012 08:44
Set right permissions for files of site
#!/bin/bash
dir=/var/www/site
user=userofsite
echo "Set permissions for $dir...";
echo "CHOWN files...";
chown -R $user:$user "$dir";
echo "CHMOD directories...";
find "$dir" -type d -exec chmod 0755 '{}' \;
@vanchelo
vanchelo / validateEmail.php
Created December 20, 2012 13:45
Проверка Email адреса на корректность
<?php
function validEmail($email) {
$isValid = true;
$atIndex = strrpos($email, "@");
if (is_bool($atIndex) && !$atIndex) {
$isValid = false;
} else {
$domain = substr($email, $atIndex+1);
$local = substr($email, 0, $atIndex);
$localLen = strlen($local);
<?php
$range=20; //Размер массива
$arrInt = range(0, $range); //Создаем массив array(0=>1, 1=>2 , 2=>3, ... (n-1)=>n); где n = $range
$arrNull=array_fill(0,$range,null); //Создаем массив с $range элементами значение которых null
$arr = array_merge($arrInt,$_SERVER,$arrNull); //Смешиваем все массивы
$find = (rand(0,1) ? 'несуществующий индекс' : array_rand($arr,1)); //Определяем какой индекс будем искать
echo "<h3>Поиск элемента с индексом <u>{$find}</u> в массиве \$arr</h3>";
<?php
$range = 200; //Размер массива
$run = 100; //Колличество поисков
$mode = isset($_GET['mode']) ? $_GET['mode'] : '';
$time = 0;
$arr = getArr($range); //Создаем массив
for($i=$run; $i>0; $i--){
$find = (mt_rand(0,1) ? 'несуществующий индекс' : array_rand($arr,1)); //Определяем какой индекс будем искать
@vanchelo
vanchelo / parseChunk
Created February 7, 2013 13:15
parseChunk for MODX Evo
<?php
/**
* parseChunk
*
* @category parser
* @version 0.1
* @license GNU General Public License (GPL), http://www.gnu.org/copyleft/gpl.html
* @param string $ChunkName Имя чанка
* @return string распарсеный чанк
* @author Agel_Nash <Agel_Nash@xaker.ru>
@vanchelo
vanchelo / modprocessor.class.php
Created March 29, 2013 20:09
modx processors class
<?php
/**
* modProcessor
*
* @package modx
*/
/**
* Abstracts a MODX processor, handling its response and error formatting.
*
* {@inheritdoc}
<?php
class keks {
private $keks;
public function getKeks() {
return $this->keks;
}
public function setKeks($keks) {
$this->keks = $keks;
@vanchelo
vanchelo / hint.js
Last active December 20, 2015 13:09 — forked from anonymous/hint.js
/*DISPLAY HINTS FOR INPUTS*/
$('input').on('focus', function() {
var hint = $(this).attr('hint');
if(hint !== undefined){
$(this).after('<div class="hint">'+hint+'</div>');
$('.hint').fadeIn('fast');
$(this).closest('.row').find('label.error').hide();
}
})
@vanchelo
vanchelo / ChangeUserGroup.php
Created October 1, 2013 22:02
Laravel 4, Sentry Операции с пользователем
# Получаем пользователя по его ID
$user = Sentry::findUserById(1);
# Получаем пользователя по его Email или логину
# $user = Sentry::findUserByLogin('email@email.com');
# Добавляем пользователя в группу
$user->addGroup(Sentry::findGroupByName('Admins'));
# Удаляем пользователя из группы
$user->removeGroup(Sentry::findGroupByName('Users'));