Skip to content

Instantly share code, notes, and snippets.

View Patricy's full-sized avatar

Kytsiuk Sergii Patricy

  • Prague, Czech Republic
View GitHub Profile
@Patricy
Patricy / example.sql
Created May 25, 2017 09:01
Last access to the table TABLENAME in SQLServer
select DB_NAME(us.[database_id]) as [db], OBJECT_NAME(us.[object_id], us.[database_id]) as [object],
MAX(us.[last_user_lookup]) as [last_user_lookup], MAX(us.[last_user_scan]) as [last_user_scan], MAX(us.[last_user_seek]) as [last_user_seek]
from sys.dm_db_index_usage_stats as us
where us.[database_id] = DB_ID() AND us.[object_id] = OBJECT_ID('TABLENAME')
group by us.[database_id], us.[object_id];
@Patricy
Patricy / main-local.php
Last active January 5, 2017 09:24
Yii2 "assets does not updates" issue
<?php
$config['components']['assetManager']['hashCallback'] = function($path){
$mostRecentFileMTime = 0;
if (is_dir($path)){
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::CHILD_FIRST);
foreach ($iterator as $fileinfo) {
if ($fileinfo->isFile() && $fileinfo->getMTime() > $mostRecentFileMTime) {
$mostRecentFileMTime = $fileinfo->getMTime();
}
}
@Patricy
Patricy / make_databases_backup.sh
Created November 6, 2015 10:47
Daily database backup
#!/bin/sh
# use on develop servers only
DAYSSTORING=14
GZIP="$(which gzip)"
BACKUPDIR=/home/patricy/backup/database
BACKUPPREFIX="all-databases"
MYSQLDUMP="$(which mysqldump)"
@Patricy
Patricy / post-merge
Created October 21, 2015 12:38
GIT hook for check after merge/pull. If some DB models (yaml) changed - it will notice user
#!/bin/sh
echo
echo "============ Migration control v1.0 (by Patricy) 21-10-2015 ==============="
RED='\033[1;31m'
GREEN='\033[1;32m'
NC='\033[0m'
LOG_CHECK_PERIOD="1 month ago"
SECONDS_CHECK=10
modelsPulled="$(git log --since="$LOG_CHECK_PERIOD" --pretty=format:"%h %ai" --name-only|grep yaml|while read line; do if [ -f $line ]; then DATE_LAST_MOD=`date -r $line +%s`; else DATE_LAST_MOD=0; fi;DATE_LAST_PULL=`date -r ./.git/FETCH_HEAD +%s`;COUNT=$(($DATE_LAST_PULL-$DATE_LAST_MOD));if [ $COUNT -lt $SECONDS_CHECK ]; then echo $line;fi;done|wc -l)"