Skip to content

Instantly share code, notes, and snippets.

@bscheshirwork
bscheshirwork / gist:88416dd46555d08fe57463624b613c56
Created April 17, 2019 09:53
nginx redirect generate. command for yii2
<?php
namespace console\controllers;
use Yii;
use yii\console\Controller;
use yii\console\ExitCode;
use yii\console\widgets\Table;
class RedirectController extends Controller
@bscheshirwork
bscheshirwork / nginx.conf
Created May 20, 2019 08:43
# кеширование изображений из версионированных папок
# кеширование изображений из версионированных папок
location ~ ^/assets/.*\.(png|jpg|gif|svg)$ {
expires max;
try_files $uri =404;
}
# раскомментируйте строки ниже во избежание обработки Yii обращений к несуществующим статическим файлам
location ~ \.(png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
try_files $uri =404;
}
@bscheshirwork
bscheshirwork / myform.js
Created January 30, 2020 09:26
yii.activeForm and jquery onSubmit for this form. Do not call twice.
$('.feedback-form__form').on('submit', (function (e) {
// first time call before first call yii.activeForm submitForm
// set $.Deferred() in submitForm ()
// second time call before second call yii.activeForm submitForm
// note: fire submit again after ajax
// don't call form twice - js validate already is true
console.log('feedback-form__form submit');
let $form = $(this),
submitButton = $('input[type="submit"]', $form),
@bscheshirwork
bscheshirwork / docker_desc.sh
Created February 28, 2020 02:47 — forked from mlinhard/docker_desc.sh
Shell script to find docker image descendants
#!/bin/bash
parent_short_id=$1
parent_id=`docker inspect --format '{{.Id}}' $1`
get_kids() {
local parent_id=$1
docker inspect --format='ID {{.Id}} PAR {{.Parent}}' $(docker images -a -q) | grep "PAR ${parent_id}" | sed -E "s/ID ([^ ]*) PAR ([^ ]*)/\1/g"
}
print_kids() {
sudo groupadd -r -g 82 alpine-www-data
groups
sudo usermod -a -G alpine-www-data $(id -un)
# exit and re-login
groups
dev sudo alpine-www-data docker
#apply to folders
sudo chown -R :dev alpine-www-data folder
sudo chmod -R g+w folder
@bscheshirwork
bscheshirwork / another-view.php
Last active May 22, 2020 13:48
yii2 DI and 2lvl config
->widget(DatePicker::class, [
// 'pluginOptions' => [
// 'autoclose' => true,
// 'format' => 'dd.mm.yyyy',
// 'todayHighlight' => true,
// ],
'removeButton' => false,
]);
@bscheshirwork
bscheshirwork / main.js
Created March 4, 2021 13:15
yii2 avoid second time send form if page not been reloaded (for example if this form call file for download)
$('form').on('beforeSubmit', function(event) {
let $form = $(this),
data = $form.data('yiiActiveForm');
if ($form.data('yiiSubmitFinalizePromise') && data.validated) {
data.validated = false;
return true;
}
return false;
});