Skip to content

Instantly share code, notes, and snippets.

find . -mtime +14 -delete
@o-shabashov
o-shabashov / config.inc.php
Created September 16, 2013 04:49
Увеличить таймаут сессии PMA
$cfg['LoginCookieValidity'] = 28800; // 8 hours
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer
@o-shabashov
o-shabashov / gist:6680529
Created September 24, 2013 04:54
Linux - to change all the directories to 755 and to change all the files to 644
to change all the directories to 755:
find /opt/lampp/htdocs -type d -exec chmod 755 {} \;
to change all the files to 644:
find /opt/lampp/htdocs -type f -exec chmod 644 {} \;
@o-shabashov
o-shabashov / sql.sql
Created May 29, 2016 22:39
SQL select where name = "A..E"
select * from brand
where substr(brand_name, 1, 1) >= 'a' and substr(brand_name, 1, 1) <= 'e'
order by brand_name ASC
@o-shabashov
o-shabashov / php.php
Created May 29, 2016 22:40
Yii2 ActiveRecord->hasAttribute VS Model->hasProperty
<?php
// class ContactForm extends Model
$contact = new ContactForm();
// class User extends \yii\db\ActiveRecord
$user = new User();
isset($contact->email); // false
$contact->hasProperty('email'); // true
@o-shabashov
o-shabashov / php.php
Created May 29, 2016 22:43
Yii2 force clean assets cache
<?php
// Global in config/web.php
'components' => [
// ...
'assetManager' => [
'forceCopy' => YII_DEBUG,
],
@o-shabashov
o-shabashov / DistanceHelper.php
Created May 29, 2016 22:45
Google Maps API Calculating route to the coordinates or name, return travel time and distance
<?php
class DistanceHelper {
/**
* @param string | float $from
* @param string | float $to
*
* @return object
*/
public static function calculate($from, $to) {
@o-shabashov
o-shabashov / php.php
Created May 29, 2016 22:49
Yii2 ActiveRecord get all records for last %interval%
<?php
$interval = 'DAY';
//$interval = 'WEEK';
//$interval = 'MONTH';
$brands = BrandExt::find()
->where([
'between',
'brand.created_at',
new Expression(sprintf('date_sub(utc_timestamp, interval 1 %s)', $interval)),
@o-shabashov
o-shabashov / php.php
Created May 29, 2016 22:50
Yii2 redirect to remembered URL
<?php
// Stored in session
Url::remember(['brands/vanity-iew', 'brand' => $brand->vanity_url], 'return-url');
// Redirect if exist
if (Url::previous('return-url')) {
return $this->redirect(Url::previous('return-url'));
}