Skip to content

Instantly share code, notes, and snippets.

@o-shabashov
o-shabashov / dev
Created May 15, 2017 04:27
/etc/resolver
nameserver 127.0.0.1
port 53535
#!/usr/bin/env python
import sys, os, re
from subprocess import check_output
# Collect the parameters
commit_msg_filepath = sys.argv[1]
if len(sys.argv) > 2:
commit_type = sys.argv[2]
else:
@o-shabashov
o-shabashov / composer.md
Created June 6, 2016 06:30
Composer set Github auth token from console

composer config -g github-oauth.github.com <oauthtoken>

This shit really needs to be documented somewhere.

@o-shabashov
o-shabashov / UserQuery.php
Created May 30, 2016 09:23
Yii2 today scope in ModelQuery
<?php
namespace app\models;
/**
* This is the ActiveQuery class for [[User]].
* @see User
*/
class UserQuery extends \yii\db\ActiveQuery
{
/**
@o-shabashov
o-shabashov / nginx.conf
Last active December 27, 2018 07:25
Nginx 1.10.* + LetsEncrypt SSL (A+) + HTTP/2 + PHP7-FPM + Force HTTPS sample config
server {
listen 80;
server_name domain.com;
root /var/www/domain.com;
location ~ /.well-known {
allow all;
}
location ~ /\.ht {
@o-shabashov
o-shabashov / php.php
Created May 29, 2016 22:52
Arrays '+' VS Yii2 ArrayHelper::merge
<?php
// $arr1
Array
(
[a] => 1
[b] => 2
[c] => 3
)
// $arr2
@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'));
}
@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 / 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:43
Yii2 force clean assets cache
<?php
// Global in config/web.php
'components' => [
// ...
'assetManager' => [
'forceCopy' => YII_DEBUG,
],