Skip to content

Instantly share code, notes, and snippets.

View onmotion's full-sized avatar
:octocat:

Alexandr Kozhevnikov onmotion

:octocat:
View GitHub Profile
@onmotion
onmotion / centering.swift
Created March 14, 2018 12:15
swift centering content inside scrollView
//centering content inside scrollView
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
let offsetY = max((scrollView.bounds.height - scrollView.contentSize.height) * 0.5, 0)
self.scrollView.contentInset = UIEdgeInsetsMake(offsetY, 0, 0, 0)
}
@onmotion
onmotion / git.md
Last active February 19, 2018 11:24
git remove all branches except master

remove all branches except master

git branch -a | grep -v "master" | sed -e 's/remotes\/origin\///g' | xargs git push origin --delete
@onmotion
onmotion / example.xml
Last active February 9, 2018 11:24
Xcode App Transport Security Exception Domains
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<false/>
<key>NSExceptionDomains</key>
<dict>
<key>cocoacasts.com</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
@onmotion
onmotion / ios keyboard auto scroll.swift
Last active February 5, 2018 12:23
ios keyboard auto scroll
var activeField: UITextField? = nil
func registerForKeyboardNotifications(){
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow), name: NSNotification.Name.UIKeyboardWillShow, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillHide), name: NSNotification.Name.UIKeyboardWillHide, object: nil)
}
func removeForKeyboardNotifications(){
NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIKeyboardWillShow, object: nil)
NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIKeyboardWillHide, object: nil)
@onmotion
onmotion / Yii2_joinWith_subquery.php
Created January 31, 2018 12:12
Yii2 joinWith subquery
<?php
$id = $this->badge_id;
return \common\models\Country::find()->joinWith(['badgeCountryAccess' => function($query) use ($id){
return $query->andOnCondition(['bca_badge_id' => $id]);
}])->orderBy('country_name')->all();
@onmotion
onmotion / BadgeForm.php
Last active January 31, 2018 11:45
Yii2 form model
<?php
namespace backend\models\forms;
use common\models\Badge;
use common\models\BadgeCountryAccess;
use Yii;
use yii\base\Model;
use yii\web\UploadedFile;
/**
html::-webkit-scrollbar {
background-image: -webkit-gradient(linear, left top, left bottom, color-stop(59%, black), color-stop(0%, rgba(255, 255, 255, 0)));
background-image: -webkit-linear-gradient(top, black 59%, rgba(255, 255, 255, 0) 0%);
background-image: linear-gradient(to bottom, black 59%, rgba(255, 255, 255, 0) 0%);
background-size: 4px 3px;
background-repeat: repeat-y;
background-position: center center;
width: .7rem;
}
html::-webkit-scrollbar-button {
@onmotion
onmotion / self signed ssl cert (for nginx).md
Last active December 2, 2017 14:36
self signed ssl cert (for nginx)
openssl req -newkey rsa:2048 -sha256 -nodes -keyout hostname.key -x509 -days 365 -out hostname.pem -subj "/C=US/ST=New York/L=Brooklyn/O=Example Brooklyn Company/CN=hostname.com" && \

openssl x509 -in hostname.pem -out hostname.crt

<?php
$result = Order::find()->select(['price', 'firstname', 'lastname'])->joinWith('user')->createCommand()->queryAll();
Array
(
[client_id] => f43e28ff
[client_name] => name
)
<?php
$dataProvider = new ActiveDataProvider([
'query' => $query->select('client.*')->joinWith(['r_cli_tt.tt'])->addSelect('SUM(r_cli_tt_potential_sellers_cnt) as potentialsSum')->groupBy(['client_id']),
]);
и соответственно добавить potentialsSum в модель